GRGlobalRouter Docs
Console

Chat / POST

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 list

Request parameters

FieldTypeRequiredDescription
modelstringYesGlobalRouter model ID that supports image output.
messagesarrayYesChat-style context.
modalitiesstring[]YesTriggers image output when image is included.
providerstringNoSpecify provider preferences.
routingobjectNoRouting preference, such as provider or strategy tags.
image_configobjectNoImage configuration, including aspect_ratio, resolution, quality, response_format, and other fields.
input_referencesobject[]NoReference image list. Each item contains a url and supports HTTP(S) URLs or data:image/base64 data URLs.
nintegerNoNumber of images to generate.
sizestringNoImage size; do not send together with resolution or aspect_ratio.
aspect_ratiostringNoAspect ratio, such as 1:1, 16:9, or 9:16.
resolutionstringNoResolution tier.
qualitystringNoQuality tier; supported values depend on the model.
stylestringNoStyle parameter; supported values depend on the model.
seedintegerNoRandom seed.
userstringNoApplication-side user identifier.
response_formatstringNoReturn url or b64_json.
output_formatstringNoArtifact format, such as png, jpeg, or webp.
backgroundstringNoBackground mode.
output_compressionintegerNoOutput compression quality from 0 to 100.
moderationobjectNoModeration configuration, when supported by the provider.
streambooleanNoWhether to return SSE streaming responses.

Request examples

Create image from Chat 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

FieldTypeRequiredDescription
idstringYesChat completion ID。
choicesobject[]YesChat response list.
choices[].message.imagesobject[]NoGenerated image list; image URLs are in image_url.url.
usageobjectNoUsage summary.
openrouter_metadataobjectNoRequest metadata.

Response example

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"
  }
}