Python AI Image Generator: Use a Text API for Prompts
If you searched for an ai image generator python setup, one thing first: this service does not draw pictures. It is a text API, and Python is a good way to use it as the prompt-writing stage in front of whatever image tool you already run.
Updated

Key points
- The API returns text only. It cannot generate, edit or upload images.
- Use the OpenAI Python SDK with the base URL and the model ID uncensored to expand short ideas into detailed image prompts.
- JSON mode gives you structured fields (prompt, negative prompt, style) that a script can pass to any image backend.
- A typical prompt-writing call costs a fraction of a cent, so you can batch thousands of them.
Short answer: this is a text API, not an image generator
An ai image generator python script normally means one of two things: a script that calls a hosted image model, or a script that runs a diffusion model on your own GPU. This site offers neither. What you get is a hosted, OpenAI-compatible text LLM API with one model, uncensored, that answers without content refusals for lawful adult use. It accepts text and returns text. There is no image generation, no image editing, no embeddings and no fine-tuning.
That still matters for image work, because most image models respond strongly to how the prompt is written. A short idea such as "a lighthouse in a storm" produces a flat result. A prompt that names the lens, the light, the palette, the camera angle and the mood produces something much closer to what you had in mind. Writing those prompts by hand is slow, and a general chat model often waters down or refuses requests that are perfectly lawful. A text model that does not refuse is a practical prompt-writing assistant.
So the useful framing is a two-stage pipeline. Stage one is this API, called from Python, which turns rough input into a finished prompt. Stage two is the image backend of your choice, which turns that prompt into pixels. The rest of this article builds stage one and shows where stage two plugs in.
It helps to be clear about what you gain from the split. Image models change quickly, and a prompt style that works well on one may need adjusting for another. If the prompt writer is a separate stage, you keep your prompt logic when you switch image tools. Only the small render() function changes. People who start with a single monolithic script that mixes the two usually end up rewriting it the first time they change backends.
One rule applies regardless of the tools you chain together: the API will not produce sexual content involving minors, and your pipeline should not try to.
Set up the Python client
The API follows the OpenAI chat completions format, so the official openai package works unchanged. You only replace the base URL and the key. Create a key on the API key page, then install the package.
pip install openai
export UNCENSORED_API_KEY="your-key-here"
A first call looks like this. The two endpoints you can use are POST /v1/chat/completions and GET /v1/models, and the SDK handles both.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.uncensoredaiimage.top/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You write detailed prompts for text-to-image models."},
{"role": "user", "content": "A lighthouse in a storm, painterly, dramatic."},
],
temperature=0.9,
)
print(resp.choices[0].message.content)
If this prints a long, descriptive paragraph, the connection works. The key travels in the Authorization: Bearer header, which the SDK sets for you. The quickstart covers the same call in curl and Node if you prefer those.
Turn one idea into a structured image prompt
Free-form text is fine for a human, but a script needs fields. JSON mode makes the model return a single JSON object, which you can parse and route. Turn it on with response_format, and describe the shape you want in the system message, because JSON mode guarantees valid JSON syntax, not a particular schema.
import json
SYSTEM = '''You are a prompt writer for text-to-image models.
Return one JSON object with these keys:
prompt: a single detailed paragraph (subject, setting, lighting, lens, palette, mood)
negative_prompt: a short comma-separated list of things to avoid
aspect_ratio: one of "1:1", "16:9", "9:16", "4:3"
Do not include text, captions or watermarks in the scene.'''
def expand(idea: str) -> dict:
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": idea},
],
response_format={"type": "json_object"},
temperature=0.8,
max_tokens=600,
)
return json.loads(resp.choices[0].message.content)
spec = expand("an abandoned greenhouse overgrown with ferns, early morning")
print(spec["prompt"])
print(spec["aspect_ratio"])
Three details make this reliable in practice. First, name the allowed values for anything you will branch on, such as the aspect ratio, so you never have to guess at spelling. Second, keep temperature between 0.7 and 1.0 for creative variety; lower it if you want near-identical output on repeated runs. Third, set seed when you need to reproduce a result while debugging, since the parameter is passed through.
Plug in the image backend
Stage two is up to you, and this API does not care which one you choose. It could be a diffusion pipeline running on your own machine, a hosted image service with its own SDK, or a ComfyUI or Automatic1111 server that you call over HTTP. Check the documentation of whichever tool you use for its exact parameters, because they differ between tools and change over time.
What stays the same is the seam between the two stages. Write one small function per backend that accepts the fields from expand() and returns image bytes or a file path. The rest of your script never needs to know which backend is active.
def render(spec: dict) -> str:
'''Send spec['prompt'] and spec['negative_prompt'] to your image backend.
Replace the body with a call to the tool you actually use.'''
raise NotImplementedError
ideas = [
"a night market seen from a rooftop, rain, neon reflections",
"a robot gardener tending bonsai, soft morning light",
]
for idea in ideas:
spec = expand(idea)
path = render(spec)
print(idea, "->", path)
Different backends accept different options, so keep the model's output generic and translate it inside render(). The aspect ratio string from the example becomes a width and height pair in one tool and a size preset in another. A small lookup table in that function is enough, and it keeps the prompt-writing code free of tool-specific details. If you want the model to adapt its wording to a given style family, say so in the system message, for example "write in short comma-separated tags" or "write in full sentences", and keep one system message per style.
Keeping the stages apart has a side benefit: you can cache the output of expand() in a file or database. If the image backend fails halfway through a batch, you rerun only the failed renders and do not pay for the text calls again.
Batching, concurrency and rate limits
Image jobs tend to arrive in bulk, so plan for limits from the start. A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 requests per minute. Go over either limit and you get HTTP 429, with the error code rate_limited for requests per minute or concurrency for too many at once. If the service is briefly overloaded it also answers 429 with a Retry-After: 5 header.
A thread pool capped at the concurrency limit, plus a retry that respects the header, covers all three cases.
import time
from concurrent.futures import ThreadPoolExecutor
from openai import RateLimitError
def expand_with_retry(idea: str, tries: int = 5) -> dict:
for attempt in range(tries):
try:
return expand(idea)
except RateLimitError:
time.sleep(5 * (attempt + 1))
raise RuntimeError("still rate limited: " + idea)
with ThreadPoolExecutor(max_workers=6) as pool:
specs = list(pool.map(expand_with_retry, ideas))
For very large jobs, write results to disk as you go. A simple approach is a JSON Lines file with one record per idea, containing the idea, the returned spec and the request ID. On restart, load the file, skip any idea that is already there, and continue. That turns a crash at item 4,000 from a disaster into a two-minute delay.
Six workers leaves headroom under the limit of 8, which matters if another script shares the same key. Responses carry the headers X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency. Log the request ID with each job. If something looks wrong, that ID is what support needs to find the call.
What a prompt-writing call costs
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit. Prompt expansion is a small job, so the numbers are low. Take a system message and idea of about 300 input tokens, and a JSON reply of about 200 output tokens.
- Input: 300 tokens × $0.15 / 1,000,000 = $0.000045
- Output: 200 tokens × $0.50 / 1,000,000 = $0.0001
- Total per call: $0.000145
A batch of 1,000 prompts costs $0.145, and 10,000 prompts cost $1.45. The text stage is rarely the expensive part of an image pipeline; your image backend will cost more per item. Failed or refused requests are not charged, so retries on errors do not add to the bill. A longer system message raises the input side, so measure with your real prompt. The cost analysis page goes through more scenarios, and the pricing page lists the top-up options. Top-ups start at $20, and payment is crypto only: USDT on TRC20 or USDC on Base.
New accounts can claim $0.50 of trial credit with one click on the API key page after sign-up. It lasts 7 days and needs no payment details. At the per-call figure above, that is enough for thousands of prompt expansions, which is plenty to test a whole pipeline.
Common mistakes
- Expecting an image back. The response is always text. If your code looks for a URL or base64 data, it will not find any.
- Trusting JSON keys. JSON mode ensures the output parses. It does not ensure your keys exist, so check with
spec.get("prompt")and retry on a miss. - Prompts that ask for text inside the picture. Many image models handle lettering poorly. Tell the writer model to avoid captions in the scene, as the system message above does.
- Ignoring the context window. It is 100,000 tokens for prompt plus completion, which is far more than prompt writing needs, but a loop that appends every previous result to the conversation will grow quickly.
- Sharing keys in client-side code. Call the API from your server or script, never from a web page that visitors can inspect.
One more point on quality. Tell the model what to leave out as clearly as what to include. Instructions such as "no more than 80 words" or "one subject only" keep prompts focused, because long prompts that name many subjects tend to give muddled pictures in most image models. Test a handful of ideas by hand, look at the images, and adjust the system message before you run a batch of thousands.
Prompts you send are not used for training. Read the privacy page for the full statement before you pipe sensitive material through.
More guides
Questions and answers
Can this API generate images from Python?
No. It is text only: chat completions in, text out. Use it to write the prompts, then send them to a separate image generator.
Which model ID do I use in the OpenAI SDK?
Use uncensored as the model, set base_url to https://api.uncensoredaiimage.top/v1 and pass your key as the api_key.
Does JSON mode work for structured image prompts?
Yes. Set response_format to {"type": "json_object"} and describe the keys you want in the system message, then parse the result with json.loads.
How do I test it without paying?
Sign up, then claim the $0.50 trial credit with one click on the API key page. It is valid for 7 days and is limited to 2 concurrent requests and 60 requests per minute.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.