Models API

Claude API for every Claude model, on one prepaid key

Call every Claude model through the native Anthropic Messages API, with streaming, extended thinking, tool use and prompt caching. Prepaid, per token.

Prepaid, no subscriptionREST or MCPOne key for models, data and agents
Claude CodeAnthropic SDKYour appAgentslovely1 keyClaude/v1/messagesclaude-opus-5.5claude-sonnet-5.5claude-haiku-5.5GPT/v1/responsesgpt-6.1-solgpt-6-astragpt-5.6-terraGemini/v1betagemini-3.1-progemini-3.8-flashgemini-3-flash

You want to call Claude from your own code or from Claude Code, pay as you go per token, and skip a separate account and invoice for every vendor. Lovely Router serves the Anthropic Messages API exactly as Anthropic defines it, so the official SDKs and Claude Code work once you change the base URL and use your Lovely Router key as the Claude API key. The same key also calls GPT and Gemini, the data tools and the browser agent.

Hand it to your AI agent

Copy this prompt into Claude Code, Cursor, Codex or any coding agent. It tells the agent where the docs are and how to use your API key.

Integrate models from Lovely Router into this project through the native Anthropic Messages API.

- Docs (read first): https://lovelyrouter.com/docs/models/anthropic.md
- Use the official Anthropic SDK and only change the base URL to https://lovelyrouter.com (or set ANTHROPIC_BASE_URL=https://lovelyrouter.com). Endpoints: POST https://lovelyrouter.com/v1/messages and /v1/messages/count_tokens, unchanged from Anthropic, so Anthropic's docs are the reference for every parameter. `Authorization: Bearer` works too.
- GET https://lovelyrouter.com/v1/models lists every model id with its price; pick one there, do not guess ids.
- Auth: read my API key from the LOVELY_API_KEY environment variable and send it as `x-api-key: $LOVELY_API_KEY`. Never print or commit the key. If it is not set, ask me to create one at https://lovelyrouter.com/app/keys.
- Billing is prepaid: every call is charged to my balance, so test with a small request before running anything large.
- Every docs page is plain Markdown; the full index is https://lovelyrouter.com/llms.txt.

My task: <describe what you want to build or get>
01

How it works

010203
  1. Create a key

    Sign up, add credit from $5, and create a key in API keys. You can give the key a spend limit, a model allow-list or a fixed channel group.

  2. Point the SDK at Lovely Router

    Set the base URL to https://lovelyrouter.com. The SDKs also read ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from the environment, so code that builds a default client needs no edits.

  3. Send a Messages request

    POST /v1/messages takes the body Anthropic documents. It reaches the model unchanged apart from the model id, and the response comes back byte for byte.

    curl https://lovelyrouter.com/v1/messages \
      -H "x-api-key: $LOVELY_API_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 HTTP caching in two sentences."}]
      }'

The key works in x-api-key, which the Anthropic SDK sends, or in Authorization: Bearer. anthropic-version and anthropic-beta are forwarded as you send them.

02

Claude API pricing, live

ModelContextInputOutputCache read
Claude Fable 5.1
claude-fable-5.1
1M$10.00$50.00$0.25
Claude Opus 5.5
claude-opus-5.5
1M$4.00$20.00$0.20
Claude Sonnet 5.5
claude-sonnet-5.5
1M$2.00$10.00$0.10
Claude Haiku 5.5
claude-haiku-5.5
1M$0.10$0.50$0.01
Claude Fable 5
claude-fable-5
1M$10.00$50.00$1.00
Claude Opus 5
claude-opus-5
1M$5.00$25.00$0.50
Claude Sonnet 5
claude-sonnet-5
1M$2.00$10.00$0.20
Claude Opus 4.8
claude-opus-4.8
1M$5.00$25.00$0.50
Claude Opus 4.7
claude-opus-4.7
1M$5.00$25.00$0.50
Claude Opus 4.6
claude-opus-4.6
1M$5.00$25.00$0.50
Claude Sonnet 4.6
claude-sonnet-4.6
1M$3.00$15.00$0.30
Claude Opus 4.5
claude-opus-4.5
200K$5.00$25.00$0.50
Claude Sonnet 4.5
claude-sonnet-4.5
1M$3.00$15.00$0.30
Claude Haiku 4.5
claude-haiku-4.5
200K$1.00$5.00$0.10

USD per 1M tokens, live from the catalog.

Live prices in US dollars per million tokens, the same numbers GET /v1/models returns without a key. Spellings other tools use resolve to the same model: claude-sonnet-5-5, anthropic/claude-sonnet-5.5 and dated ids such as claude-haiku-4-5-20251001. The model marketplace shows live availability for each model, and status shows hour-by-hour availability per channel group.

03

What the Messages API supports

Streaming

stream: true returns the standard events from message_start to message_stop. The gateway holds the stream until the first token, so a channel that fails early is replaced before anything reaches you.

Extended thinking

Send thinking and output_config as Anthropic documents them for the model: adaptive thinking with an effort level on current models, a fixed budget_tokens on Claude 4.5 and earlier. Thinking tokens are billed as output.

Tool use

Tools with a JSON Schema input_schema, tool_choice and strict pass through unchanged, as do tool_use and tool_result blocks.

Prompt caching

Mark the stable prefix with cache_control, with up to four breakpoints. Usage reports cache_creation_input_tokens and cache_read_input_tokens, each billed at its own price.

Token counting

POST /v1/messages/count_tokens is free and works with a zero balance.

Message Batches, Files and the retrieve-a-model endpoint are not served. Errors keep Anthropic's shape.

04

Prompt caching that survives load balancing

A prompt cache lives on the channel that wrote it. If each turn of a conversation landed on a different channel, each turn would pay to write the cache again. Lovely Router recognizes the turns of one conversation and sends them back to the channel that holds the cache.

You don't have to do anything: the fingerprint is the system prompt plus the first user message, which stay the same as a conversation grows. Claude Code's x-claude-code-session-id header, metadata.user_id or an x-session-id header take priority when present. A pin lasts up to an hour while the conversation is active. If its channel is busy, the turn waits briefly rather than writing a new cache; if the channel fails, the pin moves with the turn. Prompt caching shows how to check cache hits in your logs.

05

Use it from Claude Code

Claude Code speaks the Messages API, so it needs the base URL and your key:

Shell
export ANTHROPIC_BASE_URL=https://lovelyrouter.com
export ANTHROPIC_AUTH_TOKEN=$LOVELY_API_KEY
export ANTHROPIC_MODEL=claude-sonnet-5.5
claude

To keep these across sessions, put them under env in ~/.claude/settings.json, and set ANTHROPIC_DEFAULT_HAIKU_MODEL for quick background tasks. Every session stays on the channel that holds its cache. Use with your tools has the full setup, and AI coding agents covers running Claude Code, Codex CLI and Gemini CLI on one balance.

06

Recipes

Give a team Claude Code with a budget

Create one key per person with a spend limit and an allow-list of Claude ids. A key past its limit gets 402 instead of running.

Ask many questions about one long document

Put the document in a system block with cache_control and send each question as a user turn. Only the first call writes the cache.

Size a prompt before you send it

Call count_tokens with the same body minus max_tokens and compare input_tokens with the context length.

Keep billing the same on every call

Bind production keys to claude-value, so every call and every failover retry is served and billed by that group.

Compare vendors on one prompt

GPT is on the OpenAI API and Gemini on its native API, both with the same key.

07

What you pay

Claude is billed per token: uncached input, output (thinking included), cache reads and cache writes, each at the model's price per million tokens times the channel group's multiplier. Every group bills at list price today, so each Claude model costs what Anthropic lists, cache reads and writes included. The charge comes from the usage in the response and is deducted from your prepaid balance within seconds.

There is no subscription or monthly fee. Requests refused before they reach a model cost nothing, and when the gateway retries a failed call on another channel you pay only for the attempt that answered. A stream you close early pays for what was produced up to that point. Pricing lists every product on one page.

08

Frequently asked questions

?
Do I need to change my Anthropic SDK code?+

No. Set the base URL to https://lovelyrouter.com and use your Lovely Router key. Request bodies pass through unchanged, so Anthropic's documentation applies to every parameter.

Does prompt caching work through Lovely Router?+

Yes. cache_control reaches the model unchanged, and the gateway keeps each conversation on the channel that holds its cache. Cache reads and cache writes are billed at the model's cache prices.

Can I run Claude Code on a prepaid key?+

Yes. Set ANTHROPIC_BASE_URL to https://lovelyrouter.com and ANTHROPIC_AUTH_TOKEN to your key. Claude Code's session header keeps every turn of a session on one channel, so its prompt cache stays warm.

What happens when a channel is overloaded or down?+

A request waits up to 10 seconds for capacity, and a failed request is retried on another channel in the same group, up to three attempts. If every attempt fails you get a retryable 429 or 502 in Anthropic's error format, and nothing is charged.

Which Claude models can I call?+

claude-fable-5.1, claude-opus-5.5, claude-sonnet-5.5, claude-haiku-5.5 and earlier versions. GET /v1/models lists the current set with prices and needs no key.

Read the Anthropic Messages guide for every endpoint and header and Rate limits & failover for retries, or give Claude live web data through the MCP server.

One prepaid key for models, data and agents

No subscription. Top up, use what you need, see every charge in your logs.