Image Generation
Image generation lets applications send prompt-to-image requests through AISIX while keeping caller authentication, model aliases, upstream credentials, and request-side policy in one gateway path.
AISIX exposes the OpenAI image-generation route for model aliases whose configured provider is OpenAI. It resolves the caller-facing model alias, rewrites only the model field to the upstream model ID, and returns the provider's JSON image response.
In this guide, you will send an image-generation request through AISIX and review the provider requirement for this endpoint.
Prerequisites
Before starting, prepare the following:
- A running AISIX gateway that can serve proxy requests.
- A caller API key that can access the model alias.
- A model alias whose configured provider is OpenAI and whose adapter supports image generation.
Send an Image Request
Send the image-generation request through the gateway proxy with the AISIX model alias in the request body:
curl -sS -X POST "http://127.0.0.1:3000/v1/images/generations" \
-H "Authorization: Bearer YOUR_CALLER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "image-prod",
"prompt": "A minimal illustration of an AI gateway"
}' \
-o aisix-image-response.json
AISIX resolves the model alias, checks the caller API key, runs supported input policy checks on the prompt, rewrites only the model field to the upstream model ID, and forwards the request to the upstream image-generation endpoint.
The response keeps the OpenAI image-generation format:
{
"created": 1710000000,
"data": [
{
"url": "https://example.com/generated-image.png"
}
]
}
Some OpenAI image models return base64 image data instead of a URL, depending on the request and upstream model behavior.
Check that the response includes one image item:
jq '.data | length' aisix-image-response.json
The command should print:
1
OpenAI Provider Requirement
The image-generation route is provider-specific. AISIX accepts it only when the resolved model is configured with the OpenAI provider.
This is stricter than using the OpenAI-compatible adapter. An OpenAI-compatible vendor can work on the chat-completions route and still be rejected on the image-generation route because its configured provider is not OpenAI.
When the resolved model is not configured with the OpenAI provider, AISIX returns 400 before sending the request upstream.
If the resolved OpenAI-provider bridge does not implement image generation, AISIX returns 501. This is a provider capability issue, not a caller-authentication issue.
Image-Generation Behavior
Input guardrails can inspect the prompt before AISIX calls the provider. Output guardrails do not scan generated image bytes.
When the upstream image response includes recognized token usage, AISIX records it. Some image models do not return token usage. Those successful requests remain visible with zero token counts, but per-image cost details such as image count, size, and quality are not inferred by this proxy path.
If a guardrail does not block a request, check whether the prompt text contains content the configured guardrail can inspect. Generated image bytes are not inspected by output guardrails.
If a request returns 400, check whether the resolved model is configured with the OpenAI provider. If a request returns 501, check whether the resolved OpenAI-provider bridge supports image generation.
Next Steps
You have now seen how AISIX proxies OpenAI image-generation requests and where provider support is intentionally narrow. Next, continue with Rerank to review rerank request behavior through AISIX.