Claude API guide (Anthropic Messages)

TokenMilo exposes the same Messages API as Anthropic. Official SDKs and request formats work unchanged — just swap the base URL and key.

Updated 2026-11-16

1. Endpoints

Base URL (for SDKs and tools)https://api.tokenmilo.com
MessagesPOST https://api.tokenmilo.com/v1/messages
Token countingPOST https://api.tokenmilo.com/v1/messages/count_tokens

2. Authentication

Create a key on the Tokens page of the console. Send x-api-key: sk-... (or Authorization: Bearer sk-...), anthropic-version: 2023-06-01 and content-type: application/json.

3. curl

curl https://api.tokenmilo.com/v1/messages \
  -H "x-api-key: $TOKENMILO_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": "Introduce yourself in one sentence."}]
  }'

4. Python

# pip install anthropic
import os, anthropic

client = anthropic.Anthropic(base_url="https://api.tokenmilo.com", api_key=os.environ["TOKENMILO_API_KEY"])

msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Tell me a joke"}],
) as s:
    for text in s.text_stream:
        print(text, end="", flush=True)

5. Node.js

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ baseURL: "https://api.tokenmilo.com", apiKey: process.env.TOKENMILO_API_KEY });
const msg = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});
console.log(msg.content[0].text);

6. Prompt caching

Mark long, stable content as cacheable; cached tokens are billed at the cache-read rate, roughly 90% cheaper than regular input.

{
  "model": "claude-sonnet-5-5",
  "max_tokens": 1024,
  "system": [{
    "type": "text",
    "text": "<long, stable content: docs, codebase notes, rules...>",
    "cache_control": {"type": "ephemeral"}
  }],
  "messages": [{"role": "user", "content": "Using the docs above, ..."}]
}

The default TTL is 5 minutes; set "ttl": "1h" for one hour. On TokenMilo, 1-hour cache writes cost the same as 5-minute writes.

7. Error codes

StatusMeaningFix
400Bad requestCheck JSON and required fields
401Invalid keyRe-copy the key
403Insufficient quota or model not allowedTop up or check token settings
404Path or model not foundDon’t duplicate /v1; check the model list
429Rate limitedBack off and retry
5xx / 529Upstream busyRetry later

FAQ

x-api-key or Authorization: Bearer?

Both work.

Are vision, tool use and extended thinking supported?

Yes. TokenMilo serves the native Anthropic Messages API, so follow Anthropic’s request format.

Related guides

Need an API key?

Sign up at TokenMilo, top up, and create a key in the console in under a minute.

Get API key See all models