# Anthropic Protocol (Claude)

Anthropic Messages API compatible. For Claude models (GPT model names also work via auto protocol translation).

## Endpoints
| Usage | Method | Path |
| --- | --- | --- |
| Chat (REST + SSE) | POST | /v1/messages |
| Token estimate (free) | POST | /v1/messages/count_tokens |

## Supported models
claude-* (e.g. claude-haiku-4-5-20251001); gpt-* models are also supported on /v1/messages — the gateway auto-translates between Anthropic and OpenAI protocols. See GET /v1/models.

## Request body
| Param | Type | Required | Description |
| --- | --- | --- | --- |
| model | string | Yes | Model, e.g. claude-haiku-4-5-20251001 |
| messages | array | Yes | Messages (role/content) |
| max_tokens | integer | Yes | Max output tokens |
| system | string/array | — | System prompt |
| stream | boolean | — | true for SSE streaming |
| temperature / top_p / top_k | number | — | Sampling controls |
| tools / tool_choice | — | — | Tool calling |

## Streaming
Set "stream": true and receive SSE with curl -N. Events: message_start → content_block_delta → … → message_delta(usage) → message_stop.

## Non-streaming
```bash
curl -X POST "https://api.novapi.ai/v1/messages" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "max_tokens": 1024,
    "messages": [{"role":"user","content":"你好，介绍一下你自己"}]
  }'
```

## Streaming (SSE)
```bash
curl -N -X POST "https://api.novapi.ai/v1/messages" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "max_tokens": 1024,
    "stream": true,
    "messages": [{"role":"user","content":"写一首关于夏天的短诗"}]
  }'
```

## Token estimate (free)
```bash
curl -X POST "https://api.novapi.ai/v1/messages/count_tokens" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "messages": [{"role":"user","content":"估算这段话的 token"}]
  }'
```

## Response example
```json
{
  "id": "msg_xxx",
  "type": "message",
  "role": "assistant",
  "model": "claude-haiku-4-5-20251001",
  "content": [{ "type": "text", "text": "你好！我是 Claude……" }],
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 12, "output_tokens": 28 }
}
```
