Skip to main content

POST /v1/images/generations

Generates one or more images from a text description. The gateway forwards the request to the target provider (e.g. OpenAI DALL·E, Stability AI, or others) and returns image data as URLs or base64-encoded strings.

Request headers

x-portkey-provider
string
The provider to route the request to (e.g. openai, stability-ai). Required when not using a config.
x-portkey-api-key
string
Your provider API key.
x-portkey-config
string
A JSON config object or config ID that defines routing, fallbacks, retries, and more.
x-portkey-virtual-key
string
A virtual key ID from Portkey Cloud.

Request body

model
string
required
The image generation model to use (e.g. dall-e-3, dall-e-2).
prompt
string
required
A text description of the desired image. For dall-e-3, the maximum length is 4000 characters; for dall-e-2, 1000 characters.
n
integer
default:"1"
The number of images to generate. dall-e-3 supports only n=1; dall-e-2 supports up to 10.
size
string
default:"1024x1024"
The dimensions of the generated images. Supported values depend on the model:
  • dall-e-2: 256x256, 512x512, 1024x1024
  • dall-e-3: 1024x1024, 1792x1024, 1024x1792
quality
string
default:"standard"
The quality of the image. dall-e-3 supports standard and hd. dall-e-2 ignores this field.
style
string
default:"vivid"
The visual style of the image. dall-e-3 supports vivid (hyper-real) and natural (photorealistic). dall-e-2 ignores this field.
response_format
string
default:"url"
The format in which to return the image. One of url (a temporary URL valid for 60 minutes) or b64_json (base64-encoded PNG).
user
string
A unique identifier for the end user, used for monitoring and abuse detection.

Response

created
integer
Unix timestamp of when the images were created.
data
object[]
An array of generated image objects.

Code examples

curl http://localhost:8787/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "x-portkey-provider: openai" \
  -H "x-portkey-api-key: $OPENAI_API_KEY" \
  -d '{
    "model": "dall-e-3",
    "prompt": "A photorealistic image of a futuristic AI gateway in a data center",
    "n": 1,
    "size": "1024x1024"
  }'

Build docs developers (and LLMs) love