> Index: https://quebragalho.dev/en/docs/llms.txt

# 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**

```bash
# API root, without /v1
export ANTHROPIC_BASE_URL=https://api.quebragalho.dev
export ANTHROPIC_AUTH_TOKEN=$QUEBRAGALHO_API_KEY
# catalog ids; HAIKU can be a cheaper one
export ANTHROPIC_MODEL=claude-sonnet-4.6
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-sonnet-4.6
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4.6
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5.5

claude
```

- `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**

```bash
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-4.6",
    "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_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.

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

Read it in the browser: https://quebragalho.dev/en/docs/api/messages
