# Image Generation

## Generate Image

> Generates images from text prompts. Supports OpenAI models and Leonardo AI models.\
> \
> \*\*OpenAI models\*\* (gpt-image-1, gpt-image-1-mini, dall-e-2, dall-e-3) respond \*\*synchronously\*\* — the image URL is returned directly.\
> \
> \*\*Leonardo models\*\* (\`leonardo/...\`) respond \*\*asynchronously\*\* — the response contains a \`taskId\`. To retrieve the image, poll \*\*POST /api/v1/getAsyncResponse\*\* with the \`taskId\`:\
> \`\`\`json\
> { "taskId": "leo\_abc123xyz" }\
> \`\`\`\
> Poll every few seconds until the status is \`succeed\`, then use the returned image URL.

````json
{"openapi":"3.1.0","info":{"title":"FastRouter API Reference","version":"1.0.0"},"tags":[{"name":"Images","description":"Generate and edit images using AI models like DALL-E, Stable Diffusion, Flux, and more."}],"servers":[{"url":"https://api.fastrouter.ai","description":"Production API"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Key","description":"FastRouter API Key. Get yours at https://fastrouter.ai\n\nFormat: `Authorization: Bearer YOUR_API_KEY`"}}},"paths":{"/api/v1/images/generations":{"post":{"operationId":"createImage","tags":["Images"],"summary":"Generate Image","description":"Generates images from text prompts. Supports OpenAI models and Leonardo AI models.\n\n**OpenAI models** (gpt-image-1, gpt-image-1-mini, dall-e-2, dall-e-3) respond **synchronously** — the image URL is returned directly.\n\n**Leonardo models** (`leonardo/...`) respond **asynchronously** — the response contains a `taskId`. To retrieve the image, poll **POST /api/v1/getAsyncResponse** with the `taskId`:\n```json\n{ \"taskId\": \"leo_abc123xyz\" }\n```\nPoll every few seconds until the status is `succeed`, then use the returned image URL.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["prompt","model"],"properties":{"prompt":{"type":"string","description":"Text description of the desired image"},"model":{"type":"string","description":"Image generation model to use. OpenAI models return images synchronously. Leonardo models (`leonardo/...`) return a `taskId` — poll POST /api/v1/getAsyncResponse to retrieve the result.","enum":["openai/gpt-image-1","openai/gpt-image-1-mini","openai/dall-e-2","openai/dall-e-3","leonardo/phoenix-1-0","leonardo/lightning-xl","leonardo/anime-xl","leonardo/kino-xl","leonardo/vision-xl","leonardo/diffusion-xl"]},"n":{"type":"integer","minimum":1,"maximum":10,"default":1,"nullable":true,"description":"Number of images to generate. Note: Only n=1 is supported for dall-e-3"},"size":{"type":"string","nullable":true,"default":"auto","description":"Image dimensions. Supported values vary by model:\n- gpt-image-1/mini: auto, 1024×1024, 1536×1024, 1024×1536\n- dall-e-2: 256×256, 512×512, 1024×1024\n- dall-e-3: 1024×1024, 1792×1024, 1024×1792"},"quality":{"type":"string","nullable":true,"default":"auto","enum":["auto","high","medium","low","hd","standard"],"description":"Image quality level:\n- gpt-image-1/mini: auto, high, medium, low\n- dall-e-3: auto, hd, standard\n- dall-e-2: standard only"},"output_format":{"type":"string","nullable":true,"default":"png","enum":["png","jpeg","webp"],"description":"Output image format. Only supported for gpt-image-1 and gpt-image-1-mini"},"background":{"type":"string","nullable":true,"default":"auto","enum":["transparent","opaque","auto"],"description":"Background style. Only for gpt-image-1 and gpt-image-1-mini. Note: transparent requires png or webp format"},"style":{"type":"string","enum":["vivid","natural"],"default":"vivid","description":"Image style (DALL-E 3 only)"},"response_format":{"type":"string","enum":["url","b64_json"],"default":"url","description":"Format of the response data"}}}}}},"responses":{"200":{"description":"Successful response. For OpenAI models: image URL returned directly. For Leonardo models: `taskId` returned — poll POST /api/v1/getAsyncResponse to retrieve the image once ready.","content":{"application/json":{"schema":{"type":"object","properties":{"created":{"type":"integer","description":"Unix timestamp of when the image was created"},"data":{"type":"array","description":"Array of generated images","items":{"type":"object","properties":{"url":{"type":"string","format":"uri","description":"URL of the generated image (if response_format=url)"},"b64_json":{"type":"string","description":"Base64-encoded image data (if response_format=b64_json)"},"revised_prompt":{"type":"string","description":"The revised prompt used by the model (DALL-E 3 only)"}}}}}}}}},"400":{"description":"Bad Request - Invalid parameters"},"401":{"description":"Unauthorized - Invalid API key"},"429":{"description":"Rate Limit Exceeded"},"500":{"description":"Internal Server Error"}}}}}}
````


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fastrouter.ai/api-reference/image/image-generation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
