GUIDES
Claude Code and the Messages API
Point Claude Code or the Anthropic SDK at Tokely. Use the native /v1/messages endpoint with streaming, tools and prompt caching.
Run Claude Code with a Tokely key
Claude Code talks to the Anthropic Messages API. Set its base URL to Tokely and authenticate with your Tokely key; requests are billed from your Tokely balance at the published Claude rates. Map Claude Code's model slots to enabled Tokely model IDs so every request uses a supported model.
export ANTHROPIC_BASE_URL=https://api.tokely.me
export ANTHROPIC_AUTH_TOKEN=sk-your-tokely-key
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5
claudePOST /v1/messages
The endpoint accepts the Anthropic Messages request shape for enabled Claude models: system as text or blocks, user/assistant messages, streaming events, tool use and tool results, extended thinking and cache_control. Authenticate with x-api-key or Authorization: Bearer. Errors use the Anthropic error envelope.
curl https://api.tokely.me/v1/messages \
-H "x-api-key: $TOKELY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello, Tokely!"}]
}'Prompt caching
Mark reusable prefixes, such as a long system prompt or project context, with cache_control. The response usage reports cache_creation_input_tokens and cache_read_input_tokens. Cache reads are billed at the model's cache-read rate and cache writes at its cache-write rate; cached tokens are not billed again as regular input. A cache hit is not guaranteed for every request.
Limits and differences
max_tokens is required and is capped at the model's Tokely output limit. Images and PDFs must be inline base64; remote URLs and file IDs are rejected. /v1/messages/count_tokens, the Batch API, Files API and Anthropic server tools such as web search are not available. Use GET /v1/models for enabled model IDs.