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 |
| Messages | POST https://api.tokenmilo.com/v1/messages |
| Token counting | POST 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
| Status | Meaning | Fix |
|---|---|---|
| 400 | Bad request | Check JSON and required fields |
| 401 | Invalid key | Re-copy the key |
| 403 | Insufficient quota or model not allowed | Top up or check token settings |
| 404 | Path or model not found | Don’t duplicate /v1; check the model list |
| 429 | Rate limited | Back off and retry |
| 5xx / 529 | Upstream busy | Retry 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
- Quickstart — Get a key and make your first request in minutes.
- OpenAI-compatible API guide — Chat Completions and Responses with the OpenAI SDK.
- Claude Code setup — Run Claude Code with a TokenMilo key on macOS, Linux and Windows.
- Codex CLI setup — Use OpenAI Codex CLI with GPT-6 via a custom provider.
- Cursor setup — Add Claude and GPT models to Cursor with your own key.
Need an API key?
Sign up at TokenMilo, top up, and create a key in the console in under a minute.