Call a Gemini model supporting image output through the OpenAI chat format.
Request
| Item | Description |
|---|---|
| Method | POST |
| Path | /v1/chat/completions |
| Gateway URL | https://ailink.nativex.com |
| Authentication | Authorization: Bearer sk-xxxx; replace the placeholder with your API Key |
| Request format | application/json |
Replace MODEL_ID with a model from the Model Marketplace that supports this endpoint. Available models, parameters, and permissions depend on your account.
Parameters
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
model |
Body | string | Yes | A Gemini model supporting image output and chat-compatible calls |
messages |
Body | object[] | Yes | Describe the image to generate or edit in a user message |
stream |
Body | boolean | No | Whether to use SSE; this example uses false |
This is a chat-compatible endpoint. Image results do not use the Images API data[] structure. Prefer the native Gemini endpoint when you need settings such as imageConfig.
Example
curl -X POST 'https://ailink.nativex.com/v1/chat/completions' \
-H 'Authorization: Bearer sk-xxxx' \
-H 'Content-Type: application/json' \
-d '{
"model": "MODEL_ID",
"messages": [
{
"role": "user",
"content": "Draw an orange cat sitting by a window in watercolor style."
}
],
"stream": false
}'
Response
The following is a simplified response for readability. IDs, URLs, text, and usage values are illustrative.
{
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": ""
},
"finish_reason": "stop"
}
]
}
| Field or result | Description |
|---|---|
| choices[].message.content | The compatible response may contain Markdown images or data links; use the actual returned content |
Error handling
For unsuccessful responses, check the HTTP status and error body first. Verify the API Key, model name, account balance, and parameters. If rate limited, reduce concurrency and retry later.