EN ▾
Get API key

Text to Image API: Add an LLM Prompt Stage

A text to image API needs good text going in. This service does not draw anything; it is the language model that writes, expands and checks the prompts your image generator receives.

Updated

Isometric illustration of a text block passing through a converter into a picture frame, a prompt-to-image pipeline

Key points

Text processing is the hidden bottleneck in image generation pipelines, requiring reliable prompt engineering and post-processing.

Uncensored LLM APIs eliminate content refusals, ensuring consistent delivery for creative and adult-oriented image prompts.

Function calling and JSON mode enable automated, structured workflows that reduce manual intervention and errors.

Streaming via SSE and precise context window management are critical for maintaining low latency in real-time applications.

What this API does and does not do

Let us be direct, since the phrase can mislead. When people search for a text to image api they usually want an endpoint that takes a sentence and returns a picture. The API on this site is not that. It is a hosted, OpenAI-compatible text API running one open-weight model, which answers without content refusals for lawful adult use. It has no image, audio or video output, no embeddings and no fine-tuning.

That still places it in the middle of many image workflows. Most image models respond far better to a long, specific prompt than to a short one, and writing those prompts by hand for hundreds of pictures is tedious. A language model is good at exactly this job. It can turn "a lighthouse in a storm" into a paragraph with camera angle, lighting, palette and mood, and it can do so in a fixed structure your code can parse. If you want the cost view of mixing a text engine with an image model, the GPT image API analysis on this site covers it.

The model ID is uncensored, the base URL is https://api.unrestrictedimagegenerator.com/v1, and the auth header is Authorization: Bearer <key>. Any OpenAI SDK works after those two changes.

The pipeline in four steps

  1. Idea in. A user, a story outline or a spreadsheet row supplies a rough description.
  2. Prompt out. The text model rewrites it into a detailed prompt plus settings such as aspect ratio and a list of things to avoid.
  3. Render. Your code sends that prompt to the image service you use: a hosted image API, or a local Stable Diffusion or Flux install.
  4. Review and store. Optionally ask the text model to describe or check the result, then save the file with its prompt next to it.

Only step 2 touches this API. The advantage of keeping it separate is that you can swap the image side without touching the text side. If next month you prefer a different renderer, you replace one function.

A second benefit is consistency. If every picture in a series must feature the same character, the text model can hold the character sheet in its context and repeat the same description in each prompt. That is a text problem, and it is where a long context window pays off. The sibling page on pricing shows how little that costs per call.

Step 2 in code: expand an idea into structured fields

JSON mode keeps the output machine-readable. Set response_format to json_object and describe the schema in the system message. Without a schema in the instructions the model will pick its own keys, which breaks your parser.

import json
from openai import OpenAI

client = OpenAI(
    base_url="https://api.unrestrictedimagegenerator.com/v1",
    api_key="YOUR_API_KEY",
)

SYSTEM = (
    "You write prompts for an image generator. Return one JSON object with "
    "keys: prompt (string, 60-90 words, concrete visual detail), "
    "negative (string, things to avoid), aspect (one of '1:1','3:2','2:3','16:9')."
)


def make_prompt(idea):
    r = client.chat.completions.create(
        model="uncensored",
        messages=[
            {"role": "system", "content": SYSTEM},
            {"role": "user", "content": idea},
        ],
        response_format={"type": "json_object"},
        temperature=0.9,
        max_tokens=400,
    )
    return json.loads(r.choices[0].message.content)


spec = make_prompt("a lighthouse in a storm, painterly, night")
print(spec["prompt"])
print(spec["aspect"])

The same call works from curl, which is handy for a quick test before you write any Python.

curl https://api.unrestrictedimagegenerator.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","response_format":{"type":"json_object"},
       "messages":[{"role":"system","content":"Return JSON with key prompt."},
                  {"role":"user","content":"a lighthouse in a storm"}]}'

Wrap json.loads in a try block. JSON mode makes valid JSON far more likely, but if a reply is cut off by max_tokens it can still be incomplete. Retrying once is cheap, and failed requests are not charged.

Step 3: hand the prompt to your renderer

Every image service has its own request shape, so this part is a stub you fill in. The point of the stub is the contract: it takes the three fields from the text stage and returns image bytes or a file path.

from concurrent.futures import ThreadPoolExecutor


def render(spec):
    # Replace with the call to your image service or local install.
    # Send spec["prompt"], spec["negative"] and map spec["aspect"] to a size.
    raise NotImplementedError


def run(ideas):
    with ThreadPoolExecutor(max_workers=6) as pool:
        specs = list(pool.map(make_prompt, ideas))
    # Render sequentially or with the limits your image service allows.
    return [render(s) for s in specs]

Notice that prompts are made in parallel and rendering is separate. A full key allows 8 concurrent requests and 300 requests per minute, so six workers leave headroom. Image services often have much slower calls and their own limits, so do not tie the two stages to the same pool.

Letting the model call the renderer with tools

If you build a chat front end where a user says "draw me a castle at dusk", you can use tool calling instead of a fixed pipeline. Declare a function, let the model decide when to call it, run the call yourself, and return the result as a tool message. The model never touches your image service; it only fills in arguments.

tools = [{
    "type": "function",
    "function": {
        "name": "render_image",
        "description": "Create an image from a detailed prompt.",
        "parameters": {
            "type": "object",
            "properties": {
                "prompt": {"type": "string"},
                "aspect": {"type": "string", "enum": ["1:1", "3:2", "2:3", "16:9"]},
            },
            "required": ["prompt"],
        },
    },
}]

msgs = [{"role": "user", "content": "Draw me a castle at dusk."}]
r = client.chat.completions.create(
    model="uncensored", messages=msgs, tools=tools, tool_choice="auto"
)
# same client as above, base_url "https://api.unrestrictedimagegenerator.com/v1"
call = r.choices[0].message.tool_calls[0]
print(call.function.arguments)  # JSON string with prompt and aspect

Parse call.function.arguments, render the image, and append a message with role: "tool", the matching tool_call_id and a short result such as the file name. Then call the API again so the model can answer the user. Check that tool_calls is not empty before reading it; the model may answer in plain text instead.

What the text stage costs

Prices are $0.15 per 1M input tokens and $0.50 per 1M output tokens. A prompt expansion with a short system message and an idea runs around 300 input tokens, and the structured answer around 200 output tokens.

Input: 300 tokens times $0.15 per 1M is $0.000045. Output: 200 tokens times $0.50 per 1M is $0.0001. One expansion costs $0.000145. A batch of 1,000 pictures costs $0.145 in prompt writing, and 10,000 costs $1.45. The image renderer will cost far more per picture than the prompt does, so check the current pricing of whichever image service you use.

Billing is prepaid with no subscription, and credit never expires. Top-ups are any whole amount from $20 to $500, paid in USDT on TRC20 or USDC on Base, with a 5% bonus from $50, 10% from $100 and 15% from $200. New accounts can claim $0.50 of trial credit with one click on the API key page; it needs no payment and runs for 7 days. At the figures above that is roughly 3,400 prompt expansions (0.50 divided by 0.000145).

Use the same model for captions and file names

Once the prompt exists, the text stage can do more than feed the renderer. The model cannot look at a finished picture, since it works with text only, but it can write everything that travels with the picture. Ask for a short alt text, a caption of one sentence, three search tags and a file name in kebab-case, all in the same JSON object as the prompt. One call produces the lot, and the extra output is only a few dozen tokens.

This is especially useful for catalogues and story sites. A set of 500 images without descriptions is hard to search; with captions generated from the prompts that created them, it is already indexed. Store the prompt, the caption and the image path in one row of a database, and you can regenerate a single picture later without guessing what you asked for the first time.

One caution applies. If an image service rejects a prompt, the rejection comes from that service, not from this API. Keep a log of the failures with their prompts. A pattern usually shows up quickly, and you can add a line to the system message that steers the text stage away from it.

Practical advice and limits

  • Keep a style sheet. Put the palette, medium and recurring characters into the system message so every prompt stays on style.
  • Save the prompt with the image. When a picture comes out well, you can reuse the exact text. Set seed on the text call if you need repeatable prompts.
  • Mind the rules. Content is tuned for lawful adult use. Anything sexual involving minors is not allowed, and you remain responsible for what your image service accepts.
  • Watch your balance. Each response carries an X-Balance-USD header.

The full parameter list is in the API documentation. Prompts sent to the API are not used for training.

Questions and answers

What is an uncensored LLM API?

No. It is a text-only API. Use it to write and structure prompts, then send those prompts to a separate image generator.

What is an uncensored LLM API?

Image models respond better to detailed prompts, and a language model can produce them at scale in a fixed format. It also keeps a character or style consistent across a series.

What is an uncensored LLM API?

Any OpenAI-compatible SDK works. Change the base URL to the one shown in this article, use your key, and set the model to uncensored.

What is an uncensored LLM API?

Yes. After sign-up you can claim $0.50 of trial credit with one click. 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.

Get API key