Skip to content

OpenAI-compatible images

Apps built on OpenAI’s image API can switch to VelvetAPI by changing two settings: the base URL to https://api.velvetapi.dev/v1 and the API key to a VelvetAPI key. POST /v1/images/generations takes OpenAI’s request, runs a normal task (same price, screening and strikes), waits for it and answers in OpenAI’s format.

from openai import OpenAI
client = OpenAI(base_url="https://api.velvetapi.dev/v1", api_key=os.environ["VELVET_API_KEY"])
result = client.images.generate(
model="flux-3-klein",
prompt="A candid photograph of a woman with auburn hair reading on a sunlit balcony, soft morning light, 35mm film grain.",
size="1024x1024",
user="user-123",
)
print(result.data[0].url)
Field Description
model Any image model id that does text to image (GET /v1/models?task=text-to-image). gpt-image-1, dall-e-3 and dall-e-2 mean flux-3-klein. Defaults to flux-3-klein.
prompt Required.
n 1 to 4 images. Default 1.
size WIDTHxHEIGHT or auto (the model’s default). Each side is rounded to a multiple of 16 between 256 and 2048, then checked against the model’s own limits.
response_format url (default) or b64_json.
output_format png, jpeg or webp, on models that offer it.
user Your id for the end user. Send it: strikes count per end user, and without it every request from the key counts as one end user.

quality, style, background and moderation are accepted and ignored.

{
"created": 1792532435,
"data": [{ "url": "https://cdn.velvetapi.dev/o/…/0.jpg" }],
"task_id": "5b693b2d-5542-445a-a710-d16407ef51f6",
"price_usd": 0.008
}

task_id and price_usd are VelvetAPI additions. URLs are deleted after 14 days, like every output.

  • The request waits up to two minutes. If the image isn’t ready by then you get 504 timeout with the task_id; fetch the result with GET /v1/tasks/{id}.
  • A refused prompt is 422 prompt_blocked, and a task that fails is 422 generation_failed with its task_id. Neither is charged.
  • Image edits (/v1/images/edits) and video aren’t on this endpoint. Use tasks with reference_images for edits, and see Video.