Skip to content
中文

POST /v1/chat/completions

Method: POSTEndpoint: /v1/chat/completions

Official GuideOfficial API Documentation All chat models can use this interface. Change the model field to the target model name. Requires a model with image-generation support.

Request Parameters

Header Parameters

text
Content-Type
string
Required
Example:
application/json
Accept
string
Required
Example:
application/json
Authorization
string
Optional
Default Value:
Bearer {{YOUR_API_KEY}}

Body Parameters application/json

text
model
enum<string>
Required
The ID of the model to use. For details about which models support the Chat API, see
the model endpoint compatibility table.
Enum Values:
gpt-image-1
gpt-4o-image
sora_image
flux-kontext-pro
Supports all flux-kontext models; flux-kontext-dev requires a reference image.
flux
Supports all flux series
nano-banana
  // provider-specific example normalized for English documentation
dall-e-3
recraftv3
qwen-image
nano-banana-hd
doubao-seedream-4-0-250828
doubao-seededit-3-0-i2i-250628
doubao-seedream-3-0-t2i-250415
messages
array
[object]
Required
in
the chat format
to generate a chat completion message.
role
string
Optional
content
string
Optional
stream
boolean
Optional
If set, partial message deltas are streamed just like in ChatGPT. Tokens are sent as data-only
server-sent events
data: [DONE]
events as they become available, and the stream is terminated by a final message.
For sample code
, see the OpenAI Cookbook.
Example
{
"model"
:
"gpt-4o-image"
,
"stream"
:
false
,
"messages"
:
[
{
"role"
:
"user"
,
"content"
:
"Draw a cat"
}
]
}

Example Request

Shell

bash
curl --location --request POST '/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-4o-image",
    "stream": false,
    "messages": [
        {
            "role": "user",
            "content": "Draw a cat"
        }
    ]
}'

Response

🟢 200 OK

Content Type: application/json

Response Schema

text
id
string
Required
object
string
Required
created
integer
Required
choices
array
[object]
Required
index
integer
Optional
message
object
Optional
finish_reason
string
Optional
usage
object
Required
prompt_tokens
integer
Required
completion_tokens
integer
Required
total_tokens
integer
Required

Example

json
{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "\n\nHello there, how may I assist you today?"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 9,
        "completion_tokens": 12,
        "total_tokens": 21
    }
}