Create image from Chat
Requests image output from a Chat call.
POST /api/v1/chat/completions
Useful for applications that already organize context with messages. After passing `modalities: ["image"]`, image results are returned in message.images.
Back to Chat endpoint listRequest parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | GlobalRouter model ID that supports image output. |
messages | array | Yes | Chat-style context. |
modalities | string[] | Yes | Triggers image output when image is included. |
provider | string | No | Specify provider preferences. |
routing | object | No | Routing preference, such as provider or strategy tags. |
image_config | object | No | Image configuration, including aspect_ratio, resolution, quality, response_format, and other fields. |
input_references | object[] | No | Reference image list. Each item contains a url and supports HTTP(S) URLs or data:image/base64 data URLs. |
n | integer | No | Number of images to generate. |
size | string | No | Image size; do not send together with resolution or aspect_ratio. |
aspect_ratio | string | No | Aspect ratio, such as 1:1, 16:9, or 9:16. |
resolution | string | No | Resolution tier. |
quality | string | No | Quality tier; supported values depend on the model. |
style | string | No | Style parameter; supported values depend on the model. |
seed | integer | No | Random seed. |
user | string | No | Application-side user identifier. |
response_format | string | No | Return url or b64_json. |
output_format | string | No | Artifact format, such as png, jpeg, or webp. |
background | string | No | Background mode. |
output_compression | integer | No | Output compression quality from 0 to 100. |
moderation | object | No | Moderation configuration, when supported by the provider. |
stream | boolean | No | Whether to return SSE streaming responses. |
Request examples
curl "https://api.globalrouter.com/api/v1/chat/completions" \
-H "Authorization: Bearer $GR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-image",
"provider": "doubao",
"routing": { "provider": "doubao" },
"messages": [
{ "role": "user", "content": "生成一张简洁的模型网关架构图。" }
],
"modalities": ["image"],
"input_references": [
{ "url": "https://ark-project.tos-cn-beijing.volces.com/doc_image/seedream4_5_imageToimage.png" }
],
"image_config": {
"aspect_ratio": "1:1",
"resolution": "1080p",
"response_format": "url",
"output_format": "png",
"seed": 42
},
"moderation": { "strategy": "Auto" }
}'Response fields
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chat completion ID。 |
choices | object[] | Yes | Chat response list. |
choices[].message.images | object[] | No | Generated image list; image URLs are in image_url.url. |
usage | object | No | Usage summary. |
openrouter_metadata | object | No | Request metadata. |
Response example
{
"id": "chatcmpl_123",
"object": "chat.completion",
"choices": [
{
"message": {
"role": "assistant",
"content": "Generated image.",
"images": [
{
"type": "image_url",
"image_url": {
"url": "https://cdn.example.com/generated/image.png"
}
}
]
}
}
],
"openrouter_metadata": {
"provider": "doubao",
"generation_id": "req_123"
}
}