Platform

The infrastructure between your app and every model

Routing, retries, translation, metering and billing — implemented once, shared by every provider you use.

Smart routing

A single `auto` model id scores every eligible model on quality, latency and cost. Bias it per request with the X-Hanlin-Router-Mode header.

  • Context-aware eligibility
  • Tool & vision requirements
  • Per-request cost ceilings
json
{
  "model": "auto",
  "messages": [...],
  "router_mode": "cost"
}

Automatic fallback

Rate limits, timeouts and 5xx responses trigger a retry on another eligible model — preferring a different provider — before your request fails.

  • Retries on 408 / 429 / 5xx
  • No duplicate streaming
  • Reported in response headers
json
# response headers
x-hanlin-model: claude-sonnet-4-5
x-hanlin-fallback-from: gpt-5.1

Prompt caching

Cached input tokens are billed at the provider's cache-read rate instead of the full input rate, and reported separately in every usage record.

  • Up to 90% cheaper cached input
  • Per-request cache accounting
  • Visible in logs and invoices
json
usage: {
  prompt_tokens: 48210,
  prompt_tokens_details: {
    cached_tokens: 45000
  }
}

Unified billing

One prepaid balance, one invoice, one ledger across nine providers. Top up once instead of maintaining five prepaid accounts.

  • USD balance, no expiry
  • Micro-dollar precision
  • Full transaction ledger
json
transactions:
  - TOPUP   +$50.00   balance $58.21
  - CHARGE   -$0.43   balance $57.78

Usage analytics

Cost by model, key, protocol and day. Drill into any request to see tokens, latency, fallback chain and the exact price applied.

  • Per-key and per-model reports
  • CSV export
  • Request-level transparency
json
GET /api/usage/export?period=30
→ 4,219 rows, 12 columns

Multiple protocols

OpenAI chat completions, Anthropic messages and Gemini generateContent all route to the same catalog and balance.

  • Drop-in SDK compatibility
  • Cross-protocol translation
  • Tool call mapping
json
OpenAI     /v1/chat/completions
Anthropic  /v1/messages
Gemini     /v1beta/models/{m}:generateContent

Secure API keys

Keys are hashed with HMAC-SHA256 and can be scoped by spend, model list, IP address and expiry. Revocation is instant.

  • Hashed at rest
  • IP / model allowlists
  • Per-key budgets
json
hr_live_9f3c...a81d

Cost controls

Daily, monthly and per-key caps are enforced before the provider call, so a runaway agent cannot burn your balance overnight.

  • HTTP 402 at zero balance
  • Daily & monthly caps
  • Low-balance alerts
json
402 {"error":{"code": "insufficient_quota"}}
Security & operations

Built to be depended on

Production guardrails are part of the product, not an enterprise add-on.

Encrypted secrets

Provider keys AES-256-GCM encrypted at rest.

Health monitoring

Provider status and per-model success rates.

Streaming first

SSE proxying without buffering for low time-to-first-token.

Audit trail

Admin actions and balance adjustments are logged.

Put one endpoint in front of every model

Create an account, generate a key and change one base URL. That is the whole migration.

Get your API key
Features · HanlinRouter