Tera Router

Messages

Anthropic-compatible endpoint — POST /v1/messages and POST /v1/messages/count_tokens.

POST /v1/messages accepts a body exactly like Anthropic's Messages API. Perfect for the Anthropic SDK, Claude Code, and tools that speak this dialect.

Request

curl http://localhost:8080/v1/messages \
  -H "x-api-key: sk_tr_..." \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "max_tokens": 1024,
    "messages": [
      { "role": "user", "content": "Hi!" }
    ]
  }'

An Authorization: Bearer sk_tr_... header is also accepted. Responses and errors follow the Anthropic envelope:

{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "content": [{ "type": "text", "text": "Hi!" }],
  "usage": { "input_tokens": 12, "output_tokens": 5 }
}

Cross-dialect

OpenAI models can be called through this endpoint — the router translates the request to the target dialect and re-renders the response into the Anthropic format:

curl http://localhost:8080/v1/messages \
  -H "x-api-key: sk_tr_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Hi!" }]
  }'

Count tokens

POST /v1/messages/count_tokens answers locally (without calling a provider) with an estimate of ~4 characters per token:

curl http://localhost:8080/v1/messages/count_tokens \
  -H "x-api-key: sk_tr_..." \
  -H "Content-Type: application/json" \
  -d '{ "model": "anthropic/claude-sonnet-4", "messages": [] }'
{ "input_tokens": 42 }

This number is an estimate — don't use it for billing, but it's enough to answer "will it fit" before the real request.

On this page