API Reference
Claude Messages API
The Anthropic-native Messages API — use Claude models through their native protocol, compatible with the Anthropic SDK and Claude Code.
Endpoint
http
POST https://api.tokspan.com/v1/messagesQuick Examples
Use the Anthropic SDK with TokSpan as the base URL — no code changes beyond configuration:
python
from anthropic import Anthropic
client = Anthropic(
api_key="sk-your-key",
base_url="https://api.tokspan.com", # ← host root; the SDK appends /v1/messages
)
response = client.messages.create(
model="MODEL_NAME",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.content[0].text)shell
curl -X POST "https://api.tokspan.com/v1/messages" \
-H "x-api-key: sk-your-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_NAME",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'json — Response
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"content": [{
"type": "text",
"text": "Hello! How can I help you today?"
}],
"model": "MODEL_NAME",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 10,
"output_tokens": 12
}
}Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Claude model ID (e.g., claude-opus-4-8, claude-sonnet-4-6). |
| max_tokens | integer | Yes | Maximum tokens to generate. <strong>Required</strong> for the Messages API. |
| messages | array | Yes | Array of messages alternating between <code>user</code> and <code>assistant</code> roles. The first message must be from the user. |
| system | string | No | System prompt — a string or array of content blocks. |
| temperature | number | No | Sampling temperature (0–1). |
| stream | boolean | No | Enable SSE streaming. Default: <code>false</code>. |
| top_p | number | No | Nucleus sampling (0–1). |
| tools | array | No | Tool definitions for tool use. See Tool Calling. |
| tool_choice | object | No | Control tool selection: {"type": "auto"} or a specific tool. |
| thinking | object | No | Extended thinking config: {"type": "enabled", "budget_tokens": 1024}. Budget must be ≥1024 and less than max_tokens. |
System Prompts
Pass the system prompt as a top-level <code>system</code> field (not a message):
json
{
"model": "MODEL_NAME",
"max_tokens": 1024,
"system": "You are a helpful assistant that always answers in French.",
"messages": [{"role": "user", "content": "What is the capital of France?"}]
}Streaming (SSE)
Set stream: true to receive Anthropic SSE events (message_start, content_block_delta, message_stop, etc.).
shell
curl -X POST "https://api.tokspan.com/v1/messages" \
-H "x-api-key: sk-your-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_NAME",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Tell me a story."}],
"stream": true
}'Configuration: Set the Anthropic SDK's
base_url to https://api.tokspan.com — the SDK appends /v1/messages itself. Authentication accepts both x-api-key + anthropic-version headers (Anthropic-native) and Authorization: Bearer. The Anthropic SDK handles this automatically.