Messages (Anthropic-Compatible)
Anthropic-compatible endpoint for sending messages. Use this with the Anthropic SDK or Claude-style API clients.
POST
/v1/messagesCreate a message completion with automatic model routing (Anthropic format).
Request
Headers
| Header | Required | Description |
|---|---|---|
x-api-key | Yes* | Your API key (Anthropic SDK style) |
Authorization | Yes* | Bearer token (OpenAI style alternative) |
Content-Type | Yes | application/json |
*Either x-api-key or Authorization: Bearer is required.
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Virtual model (ant:auto) or real model name |
messages | array | Yes | Array of message objects (user/assistant roles) |
max_tokens | integer | Yes | Maximum tokens to generate |
system | string | No | System prompt |
stream | boolean | No | Stream response as SSE events |
temperature | number | No | Sampling temperature (0-1) |
tools | array | No | Tool definitions (Anthropic format) |
Example Request
curl -X POST https://antbase.ai/v1/messages \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "ant:auto",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Explain recursion in programming."}
]
}'Response
Response Body
{
"id": "msg_abc123xyz",
"type": "message",
"role": "assistant",
"model": "anthropic/claude-haiku-4-5",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself..."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 25,
"output_tokens": 150
}
}Response Headers
| Header | Description |
|---|---|
X-Antbase-Classifier | How the model was selected (auto, virtual, passthrough) |
Streaming
Set "stream": true to receive Server-Sent Events with Anthropic event types.
event: message_start
data: {"type":"message_start","message":{"id":"msg_123","type":"message","role":"assistant","model":"ant:auto","content":[],"stop_reason":null,"usage":{"input_tokens":25,"output_tokens":0}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" world!"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":15}}
event: message_stop
data: {"type":"message_stop"}Tool Use
Define tools using Anthropic's format. ANT converts these internally.
{
"model": "ant:auto",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "What's the weather in Paris?"}],
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a location",
"input_schema": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "City name" }
},
"required": ["location"]
}
}
]
}SDK Usage
Use the official Anthropic SDK with a custom base URL:
# Python
import anthropic
client = anthropic.Anthropic(
base_url="https://antbase.ai", # No /v1 suffix
api_key="ant_your-api-key",
)
message = client.messages.create(
model="ant:auto",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(message.content[0].text)// TypeScript
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
baseURL: 'https://antbase.ai',
apiKey: process.env.ANT_API_KEY,
});
const message = await client.messages.create({
model: 'ant:auto',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(message.content[0].text);OpenAI vs Anthropic Format
ANT supports both API formats. Choose based on your SDK preference:
| Feature | OpenAI (/v1/chat/completions) | Anthropic (/v1/messages) |
|---|---|---|
| Auth header | Authorization: Bearer | x-api-key (or Bearer) |
| System prompt | In messages array | Separate "system" field |
| max_tokens | Optional | Required |
| Response content | String | Content blocks array |
| Stream events | data: only | event: + data: |