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
claude

POST /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.

EXPLORE DOCUMENTATION

IntroductionConnect your app to AI models through one familiar API. This is your guide to building with Tokely.QuickstartMake your first Tokely request in three steps.API keysConnect securely with a key from your Tokely dashboard.ModelsChoose an available model and use its exact ID in your request.PlaygroundUse the Tokely Playground to test prompts before writing code.Use your existing appConnect an existing OpenAI-compatible application to Tokely.Chat CompletionsGenerate responses from text messages and supported inline images or PDFs.ResponsesUse stateless text and supported multimodal input with the Responses API.EmbeddingsTurn text into vectors for search, RAG, clustering and classification with the OpenAI-compatible /v1/embeddings endpoint.Claude Code and the Messages APIPoint Claude Code or the Anthropic SDK at Tokely. Use the native /v1/messages endpoint with streaming, tools and prompt caching.Images and PDFsSend inline images and PDFs to compatible models through Chat Completions or Responses.Images, video & audioGenerate media with your Tokely API key and account balance.Errors & limitsDiagnose failed requests and keep your integration within service limits.StreamingDisplay generated text as it arrives with server-sent events.Function callingLet a model request a function, then execute it in your application.Structured outputRequest JSON output or a defined schema from a compatible model.Usage & billingModel prices, account balance and output reservations.WebhooksTokely webhook events, HMAC signature verification, delivery retries and replay behavior.
Use Tab to browse results ESC to close