POST
/
v1
/
chat
/
completions
Chat Completions Vision Base64 (Stream)
curl --request POST \
  --url https://api.example.com/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "stream": true,
  "max_tokens": 123,
  "temperature": 123,
  "detail": "<string>"
}
'
Create a model response that can understand and analyze base64 encoded images with streaming enabled.

Overview

This endpoint allows you to send base64 encoded images directly in the request body instead of using URLs. This is useful when you have local images or want to avoid hosting images externally.

Authentication

All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY

Request Parameters

model
string
required
ID of the model to use. Must be a vision-capable model like gpt-4-vision-preview, gpt-4o, or gpt-4o-mini.
messages
array
required
A list of messages with base64 encoded image content.
stream
boolean
required
Must be set to true for streaming responses.
max_tokens
integer
Maximum number of tokens to generate in the response.
temperature
number
default:"1"
Sampling temperature between 0 and 2.
detail
string
default:"auto"
Image detail level: low, high, or auto.

Request Example

curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "text", "text": "What is in this image?"},
          {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."}}
        ]
      }
    ],
    "stream": true,
    "max_tokens": 1000
  }'

Base64 Image Format

The base64 image URL should follow this format:
data:image/{format};base64,{base64_encoded_data}
Supported formats:
  • image/jpeg
  • image/png
  • image/gif
  • image/webp

Response Example (SSE Stream)

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"The image shows"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Available Models

  • gpt-4-vision-preview
  • gpt-4o
  • gpt-4o-mini