Chat Completions
The main endpoint for sending messages and receiving AI responses. Fully OpenAI-compatible.
POST
/v1/chat/completionsCreate a chat completion with automatic model routing.
Request
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer token with your API key |
Content-Type | Yes | application/json |
X-Antbase-Source | No | Client identifier for analytics |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Virtual model (ant:auto) or real model name |
messages | array | Yes | Array of message objects |
stream | boolean | No | Stream response as SSE events |
temperature | number | No | Sampling temperature (0-2) |
max_tokens | integer | No | Maximum tokens to generate |
tools | array | No | Function definitions for tool use |
Example Request
curl -X POST https://antbase.ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "ant:auto",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain recursion in programming."}
],
"temperature": 0.7,
"max_tokens": 500
}'Response
Response Body
{
"id": "chatcmpl-abc123xyz",
"object": "chat.completion",
"created": 1708123456,
"model": "anthropic/claude-haiku-4-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Recursion is a programming technique where a function calls itself..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}ANT Response Headers
| Header | Example | Description |
|---|---|---|
X-Antbase-Model | anthropic/claude-haiku-4-5 | Actual model used |
X-Antbase-Virtual-Model | ant:auto | Requested virtual model |
X-Antbase-Task-Type | coding | Detected task type |
X-Antbase-Complexity | medium | simple, medium, or complex |
X-Antbase-Tokens-Saved | 45 | Tokens saved by optimization |
Streaming
Set "stream": true to receive Server-Sent Events.
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"}}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"}}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Tool Use (Function Calling)
Define tools for the model to use. ANT passes these to the underlying model.
{
"model": "ant:auto",
"messages": [{"role": "user", "content": "What's the weather in Paris?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "City name" }
},
"required": ["location"]
}
}
}
]
}