Developer documentation

Integrate TokenRealm in minutes.

Use the same TokenRealm credential for Claude Code and direct API requests. Your upstream provider credentials remain server-side.

Claude Code

Configure two environment variables.

Generate a tr_live_... key in the TokenRealm dashboard, then point Claude Code to the TokenRealm API origin.

export ANTHROPIC_BASE_URL="https://api.tokenrealm.fun"
export ANTHROPIC_API_KEY="tr_live_your_key"
claude

Keep your TokenRealm API key private. Rotate or revoke it from the dashboard if it is exposed.

Messages API

Send a standard message request.

curl https://api.tokenrealm.fun/v1/messages \
  -H "x-api-key: tr_live_your_key" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "messages": [
      {"role":"user","content":"Explain this repository."}
    ]
  }'
POST /v1/messagesGenerate messages
POST /v1/messages/count_tokensCount request tokens
GET /v1/modelsList exposed models
Models

Use full IDs or aliases.

TokenRealm currently exposes Fable 5.1, Opus 5.5, Sonnet 5.5, and Haiku 5.5. Short aliases resolve to the current model in each family.

"model": "sonnet"

// resolves to:
"model": "claude-sonnet-5-5"
See the model comparison →
Routing

Automatic by default, configurable per key.

Your API key can stay in automatic mode or be pinned to a configured provider from the dashboard. For debugging or advanced workflows, a request can also specify a provider override.

x-tokenrealm-provider: aws

Provider options only work when the corresponding upstream integration has been configured by the operator.

Metering

Usage is reconciled after each request.

The gateway reserves an estimated amount before an upstream call, records returned usage metadata, then refunds any unused reservation. Recent usage appears in your dashboard.

Input

Prompt tokens and supported cache metadata.

Output

Tokens generated by the model.

Balance

Debited from prepaid TokenRealm credits.

Operational guidance

Keep integrations secure and debuggable.

  • Store tr_live_... keys in environment variables or a secrets manager.
  • Use separate keys for separate machines or applications when possible.
  • Revoke an exposed key immediately from the dashboard.
  • Inspect HTTP status and returned error bodies before retrying.
  • Use idempotent application logic for workflows that may retry automatically.