API reference
Messages
POST/v1/messages
The Anthropic format, with and without streaming. It is the route for Claude Code and the Anthropic SDK, with the same API key and the same balance as chat.
Point Claude Code here
Export the variables and run claude. The base is the API root, without /v1.
# API root, without /v1export ANTHROPIC_BASE_URL=https://api.quebragalho.devexport ANTHROPIC_AUTH_TOKEN=$QUEBRAGALHO_API_KEY# catalog ids; HAIKU can be a cheaper oneexport ANTHROPIC_MODEL=claude-sonnet-5.5export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-sonnet-5.5export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5.5export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5.5claudeANTHROPIC_AUTH_TOKENsends the key as a Bearer token and works even with a saved Anthropic login.- The three
ANTHROPIC_DEFAULT_…_MODELvariables cover subagents and background tasks. Without them, Claude Code asks for ids that may not exist in the catalog. - To check, run
/statusinside Claude Code: it shows the base URL and the credential in use.
Do not set CLAUDE_CODE_MAX_OUTPUT_TOKENS. The cap cuts off reasoning models mid-answer. On claude-* ids, Claude Code asks for up to 128K output tokens and the hold covers that cap; with a low balance, the request comes back 402. In the end, you only pay for what was generated.
More Claude Code details
ANTHROPIC_MODELis the conversation model.ANTHROPIC_API_KEYalso works, but interactive mode asks for approval before using it.- The
unrecognized_modelwarning shows up for ids that are not Anthropic's. You can ignore it.
Direct call
Without Claude Code, the route accepts the Anthropic API body. The key goes in x-api-key or in Authorization: Bearer.
curl https://api.quebragalho.dev/v1/messages \ -H "x-api-key: $QUEBRAGALHO_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 RAG in 3 lines"}] }'| Route | What it does |
|---|---|
POST /v1/messages | Anthropic Messages, with and without streaming. |
POST /v1/messages/count_tokens | Estimates the input tokens. Not billed. |
In the Anthropic SDK, pass https://api.quebragalho.dev as base_url, without /v1: the SDK appends the route.
What differs from Anthropic
Under the hood, the request becomes the same chat request. Almost everything carries over. What does not:
- Function tools work. Provider-hosted ones, such as web search, are ignored.
max_tokensabove your plan's cap is lowered to the cap.cache_controland the signature ofthinkingblocks are not preserved. Prompt caching works as in chat.documentblocks are rejected with 400.
Errors
In the Anthropic format, with the types Claude Code uses to decide whether to stop or retry.
| Situation | Response | What the client does |
|---|---|---|
| Insufficient balance | 402 billing_error | Stops right away, without retrying. |
| Conversation longer than the context | 400 invalid_request_error | Recognizes the full context and compacts. |
| Missing or invalid key | 401 authentication_error | Stops. |
| Per-minute or concurrency limit | 429 rate_limit_error | Waits for Retry-After. |
| Provider failure or slowness | 5xx api_error | Retries on its own. |
502 and 504 responses arrive as 503: Cloudflare, in front of the API, swaps those statuses. Read the type and the code in the body, not just the status.