API Reference

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.

httpRequest
POST https://infinityrouter.qd.je/v1/messages
x-api-key: inf_live_...
anthropic-version: 2023-06-01
Content-Type: application/json

Request Body Parameters

Parameters
ParameterTypeRequiredDescription
modelstringYesCanonical ID from the model catalog (e.g. claude-sonnet-5, deepseek-chat).
messagesarrayYesArray of message objects with role (user or assistant) and content blocks.
max_tokensintegerYesMaximum completion tokens to generate (enforced by the Messages specification).
systemstring | arrayNoTop-level system instructions passed directly to models.
streambooleanNoWhen true, returns standard Anthropic SSE message stream events.
temperaturenumberNoSampling temperature between 0.0 and 1.0. Default 1.0.
toolsarrayNoList of tool definitions with name, description, and input_schema.

Python Example (Anthropic SDK)

pythonanthropic_example.py
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)

typescriptanthropic_example.ts
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)

json200 OK
{
  "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

HTTP Status Codes
StatusCodeDescription
200OKSuccessful completion or streaming message.
400invalid_requestMalformed payload, missing max_tokens, or schema validation issue.
401authentication_failedMissing, invalid, or revoked API key.
402insufficient_creditsAccount balance cannot cover token reservation hold.
404model_not_foundRequested canonical model ID does not exist.
429rate_limitedKey throughput limit exceeded (returns Retry-After header).
502upstream_failureDownstream AI provider returned an unexpected error.
503no_capacityAll upstream routes for requested model are currently unavailable.