Skip to content
quebragalho/docs

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.

Terminal
# 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.5claude
  • ANTHROPIC_AUTH_TOKEN sends the key as a Bearer token and works even with a saved Anthropic login.
  • The three ANTHROPIC_DEFAULT_…_MODEL variables cover subagents and background tasks. Without them, Claude Code asks for ids that may not exist in the catalog.
  • To check, run /status inside 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_MODEL is the conversation model.
  • ANTHROPIC_API_KEY also works, but interactive mode asks for approval before using it.
  • The unrecognized_model warning 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
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"}]  }'
RouteWhat it does
POST /v1/messagesAnthropic Messages, with and without streaming.
POST /v1/messages/count_tokensEstimates 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_tokens above your plan's cap is lowered to the cap.
  • cache_control and the signature of thinking blocks are not preserved. Prompt caching works as in chat.
  • document blocks are rejected with 400.

Errors

In the Anthropic format, with the types Claude Code uses to decide whether to stop or retry.

SituationResponseWhat the client does
Insufficient balance402 billing_errorStops right away, without retrying.
Conversation longer than the context400 invalid_request_errorRecognizes the full context and compacts.
Missing or invalid key401 authentication_errorStops.
Per-minute or concurrency limit429 rate_limit_errorWaits for Retry-After.
Provider failure or slowness5xx api_errorRetries 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.