Get API key

Text to image

View as Markdown

OpenAI-compatible endpoint for generating images from a text prompt.

PrivateMind has an OpenAI-compatible endpoint that generates an image from a text prompt.

Tip

In Python, the PrivateMind SDK wraps this endpoint in one typed call: see Image generation in the Python SDK.

Generate an image

Send a model id, a prompt and a size to POST /v1/images/generations.

cURL
curl -s "https://api.privatemind.com/v1/images/generations" \
  -H "Authorization: Bearer $PMIND_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cosmos3-super-text2image",
    "prompt": "a red panda on a mossy log in a misty forest at sunrise, photorealistic",
    "size": "1024x1024"
  }'
  • model (required): an image model id. Image models have model_type: image-gen in GET /v1/models. The alias t2i points to the text-to-image model.
  • prompt (required): a description of the image to generate.
  • size (required): the output resolution as WIDTHxHEIGHT, for example 1024x1024. A missing or malformed value returns 400.
  • n (default 1): number of images to generate.
  • negative_prompt (optional): what to keep out of the image.
  • num_inference_steps (default 50): diffusion steps. Fewer is faster; more can refine detail.
  • guidance_scale (default 4.0): how strongly the image adheres to the prompt.
  • seed (optional): set it for reproducible output; leave it out for a random image each call.
  • response_format (default b64_json): url is not supported.

Response

Each image comes back as a base64-encoded PNG in data[].b64_json, in OpenAI's images format:

JSON
{
  "created": 1781481050,
  "data": [
    { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }
  ]
}

Decode it to a file:

Python
import base64, json, requests, os

resp = requests.post(
    "https://api.privatemind.com/v1/images/generations",
    headers={"Authorization": f"Bearer {os.environ['PMIND_KEY']}"},
    json={
        "model": "cosmos3-super-text2image",
        "prompt": "a red panda on a mossy log in a misty forest at sunrise, photorealistic",
        "size": "1024x1024",
    },
    timeout=300,
)
resp.raise_for_status()
img = base64.b64decode(resp.json()["data"][0]["b64_json"])
open("out.png", "wb").write(img)
Note

Generation is synchronous: the request stays open until the image is ready. One 1024x1024 image usually takes a few seconds. More steps or a larger size take longer, so set a generous client timeout.

Content safety

Image models may apply a content-safety guardrail, which classifies unsafe content and blurs faces, before returning results. A prompt or image flagged as unsafe is rejected with an error.

Where next