API Reference
Anthropic API
Native Anthropic Messages API compatibility
Anthropic Messages Endpoint
Router9 provides a native Anthropic-compatible endpoint for tools that use the Anthropic SDK directly.
POST /anthropic/v1/messagesRequest Headers
| Header | Required | Description |
|---|---|---|
x-api-key | Yes | sk-r9k-your-key |
Content-Type | Yes | application/json |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g. claude-3-sonnet) |
max_tokens | number | Yes | Maximum tokens to generate |
messages | array | Yes | Conversation messages |
stream | boolean | No | Enable streaming (default: false) |
Example Request
curl https://api.router9.com/anthropic/v1/messages \
-H "x-api-key: sk-r9k-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-sonnet",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Explain recursion briefly." }
]
}'Response
{
"type": "message",
"id": "msg-abc123",
"content": [
{
"type": "text",
"text": "Recursion is when a function calls itself to solve a problem by breaking it into smaller instances of the same problem, with a base case to stop the recursion."
}
],
"model": "claude-3-sonnet",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 12,
"output_tokens": 38
}
}Error Response
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "model, max_tokens, and messages are required"
}
}Streaming
Set stream: true to receive Anthropic-format streaming events. Router9 automatically transforms the upstream response into the correct Anthropic SSE format.
When to Use This Endpoint
Use /anthropic/v1/messages when:
- Your application uses the Anthropic Python or TypeScript SDK
- You need Anthropic-native response formats (content blocks, stop_reason, etc.)
For all other cases, use the Chat Completions endpoint which works with any OpenAI-compatible client.