# Anthropic-compatible API

> 7API's Anthropic Messages API at https://7api.st/v1/messages. Works with the Anthropic SDK and Claude Code, supports streaming, tools, extended thinking, prompt caching and token counting for every model.


7API implements the Anthropic **Messages API**. The Anthropic SDKs, Claude Code and other Anthropic-format clients work unchanged once you set the base URL and key. Non-Claude models (GLM, DeepSeek, Kimi, GPT, Grok, Gemini) are reachable on this format too.

```text
Base URL:  https://7api.st          (no /v1 — the SDK adds /v1/messages)
Header:    x-api-key: sk-your-key   (Authorization: Bearer also works)
```

## Messages

`POST /v1/messages`

```bash
curl https://7api.st/v1/messages \
  -H "x-api-key: $SEVENAPI_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 a mutex in one paragraph."}]
  }'
```

```python
from anthropic import Anthropic
client = Anthropic(base_url="https://7api.st", api_key="sk-your-key")
msg = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=2048,
    system="You are a senior reviewer.",
    messages=[{"role": "user", "content": "Review: def add(a,b): return a-b"}],
)
print(msg.content[0].text, msg.usage)
```

### Supported features

| Feature | Notes |
|---|---|
| `system`, `messages`, `max_tokens` | `max_tokens` defaults to 16,384 if omitted. The maximum is 131,072. |
| `stream: true` | Standard Anthropic SSE events. See [Streaming](https://7api.st/docs/streaming). |
| `tools`, `tool_choice` | Tool use on every model |
| `thinking` | Adaptive thinking on Claude models. `{"type":"enabled","budget_tokens":N}` is accepted on `claude-opus-4-6` only. |
| `output_config.effort` | Claude Code's effort control. See [Reasoning effort](https://7api.st/docs/reasoning-effort). |
| `cache_control` | Passed through. See [Prompt caching](https://7api.st/docs/prompt-caching). |
| Images | `image` content blocks on vision models |
| `anthropic-beta` | Forwarded. `context-1m-2025-08-07` is added automatically for `[1m]` model names. |

`POST /v1/messages/streaming` is an alias that always streams.

### Usage fields

```json
"usage": {
  "input_tokens": 12,
  "cache_creation_input_tokens": 0,
  "cache_read_input_tokens": 48211,
  "output_tokens": 377
}
```

As at Anthropic, `input_tokens` excludes cached tokens. Billing is described in [Prompt caching](https://7api.st/docs/prompt-caching).

## Count tokens

`POST /v1/messages/count_tokens` takes the same body as `/v1/messages` and returns `{"input_tokens": N}`. The count is a fast local estimate, and it's free. It still needs a positive balance, like other generation endpoints. Claude Code calls this endpoint before compacting a conversation.

## Using non-Claude models

Send any catalog ID as `model`:

```bash
curl https://7api.st/v1/messages \
  -H "x-api-key: $SEVENAPI_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "max_tokens": 512, "messages": [{"role": "user", "content": "hi"}]}'
```

Clients that only accept model names beginning with `claude-` can add that prefix to any model, for example `claude-glm-5.3` or `claude-gpt-6.1-sol`. See [Model IDs](https://7api.st/docs/model-ids).

## Errors

Generation errors on this endpoint use Anthropic's shape:

```json
{ "type": "error", "error": { "type": "overloaded_error", "message": "…" } }
```

See [Errors](https://7api.st/docs/errors) for every status code.
