Chat API (Image Analysis)
Short description: Chat interface that accepts mixed image and text inputs, suitable for image understanding and visual Q&A. Models must support image analysis (e.g., multimodal models like
gpt-4o).
Overview
- Method:
POST - Path:
/v1/chat/completions - Content-Type:
application/json
Authentication
Supports common header-based authentication formats:
- OpenAI:
Authorization: Bearer sk-xxx - Anthropic:
x-api-key: sk-xxx(may requireanthropic-version) - Google:
x-goog-api-key: sk-xxx
Request Examples
Body parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | yes | Model name that supports image analysis, e.g. gpt-4o |
| messages | array<object> | yes | Array of chat messages; each item includes role 与 content,content can be text or image references |
| temperature | number | no | Sampling temperature (0-2) |
| top_p | number | no | Nucleus sampling threshold |
| stream | boolean | no | Whether to stream responses |
| max_tokens | number | no | Max generated tokens (default example uses 300) |
| n | number | no | Number of candidate completions |
| presence_penalty | number | no | Presence penalty (-2.0 ~ 2.0) |
| frequency_penalty | number | no | Frequency penalty (-2.0 ~ 2.0) |
| logit_bias | object | no | Logit bias mapping |
| user | string | no | End-user identifier |
| stop | string or array | no | Stop sequence(s) |
About
contentinmessages:
- Text example:
{ "type": "text", "text": "What is this?" } - Image example:
{ "type": "image_url", "image_url": { "url": "https://example.com/img.jpg" } }Supportsdata:base64 URLs or network URLs.
curl example
bash
curl -X POST "https://api.gpt.ge/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxx" \
-d '{
"model": "gpt-4o",
"messages": [
{"role":"user","content":[{"type":"text","text":"What is this?"}]},
{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,...(base64 omitted)..."}}]}
],
"max_tokens": 300,
"temperature": 0.5
}'JavaScript (fetch) example
javascript
fetch('https://api.gpt.ge/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxx'
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{ role: 'user', content: [{ type: 'text', text: 'What is this?' }] },
{ role: 'user', content: [{ type: 'image_url', image_url: { url: 'https://example.com/img.jpg' } }] }
],
max_tokens: 300,
temperature: 0.5
})
}).then(r => r.json()).then(console.log)Python example (requests)
python
import requests
payload = {
'model': 'gpt-4o',
'messages': [
{'role': 'user', 'content': [{'type': 'text', 'text': 'What is this?'}]},
{'role': 'user', 'content': [{'type': 'image_url', 'image_url': {'url': 'https://example.com/img.jpg'}}]}
],
'max_tokens': 300,
'temperature': 0.5
}
resp = requests.post('https://api.gpt.ge/v1/chat/completions', headers={'Content-Type':'application/json','Authorization':'Bearer sk-xxxx'}, json=payload)
print(resp.json())Response example (200)
json
{
"id": "chatcmpl-A7ETdn5hnbTjpw9dtRifjMFZYcdFW",
"object": "chat.completion",
"created": 1726287309,
"model": "gpt-4o-2024-05-13",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This is a cartoon-style portrait of an elderly man with white hair and a beard, smiling brightly and wearing a blue outfit.",
"refusal": null
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 265,
"completion_tokens": 46,
"total_tokens": 311,
"completion_tokens_details": { "reasoning_tokens": 0 }
},
"system_fingerprint": "fp_992d1ea92d"
}