POST /v1/messages
Native Anthropic Messages dialect. Drop InfinityRouter directly into official Anthropic SDKs with zero code changes.
Endpoint & Headers
The gateway accepts standard Anthropic authentication headers (x-api-key) as well as standard Bearer tokens. Both /v1/messages and /messages are routed identically.
POST https://infinityrouter.qd.je/v1/messages x-api-key: inf_live_... anthropic-version: 2023-06-01 Content-Type: application/json
Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Canonical ID from the model catalog (e.g. claude-sonnet-5, deepseek-chat). |
| messages | array | Yes | Array of message objects with role (user or assistant) and content blocks. |
| max_tokens | integer | Yes | Maximum completion tokens to generate (enforced by the Messages specification). |
| system | string | array | No | Top-level system instructions passed directly to models. |
| stream | boolean | No | When true, returns standard Anthropic SSE message stream events. |
| temperature | number | No | Sampling temperature between 0.0 and 1.0. Default 1.0. |
| tools | array | No | List of tool definitions with name, description, and input_schema. |
Python Example (Anthropic SDK)
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://infinityrouter.qd.je/v1",
api_key=os.environ.get("INFINITY_API_KEY"),
)
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
system="You are a senior infrastructure engineer.",
messages=[
{"role": "user", "content": "How does multi-provider routing prevent downtime?"}
],
)
print(message.content[0].text)TypeScript Example (Anthropic SDK)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
baseURL: "https://infinityrouter.qd.je/v1",
apiKey: process.env.INFINITY_API_KEY,
});
async function main() {
const message = await anthropic.messages.create({
model: "claude-sonnet-5",
max_tokens=1024,
system: "You are a concise assistant.",
messages: [{ role: "user", content: "Summarize AI cost optimization." }],
});
console.log(message.content[0]);
}
main();Example Response (Non-Streaming)
{
"id": "req_a1b2c3d4e5f6",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Multi-provider routing automatically switches to healthy alternative upstreams when a primary provider experiences downtime or rate limits."
}
],
"model": "claude-sonnet-5",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 18,
"output_tokens": 26
}
}Response Status Codes
| Status | Code | Description |
|---|---|---|
| 200 | OK | Successful completion or streaming message. |
| 400 | invalid_request | Malformed payload, missing max_tokens, or schema validation issue. |
| 401 | authentication_failed | Missing, invalid, or revoked API key. |
| 402 | insufficient_credits | Account balance cannot cover token reservation hold. |
| 404 | model_not_found | Requested canonical model ID does not exist. |
| 429 | rate_limited | Key throughput limit exceeded (returns Retry-After header). |
| 502 | upstream_failure | Downstream AI provider returned an unexpected error. |
| 503 | no_capacity | All upstream routes for requested model are currently unavailable. |