Chat / Text
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 |
Authentication
Authorization: Bearer <API_KEY> Content-Type: application/json
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 Parameters
| Param | Type | Required | Description |
|---|---|---|---|
| model | string | Required | Model, e.g. claude-haiku-4-5-20251001 |
| messages | array | Required | Messages (role/content) |
| max_tokens | integer | Required | 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 (SSE)
Set "stream": true and receive SSE with curl -N. Events: message_start → content_block_delta → … → message_delta(usage) → message_stop.
Request Example
Non-streaming
curl -X POST "https://api.cqtai.com/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)
curl -N -X POST "https://api.cqtai.com/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)
curl -X POST "https://api.cqtai.com/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
{
"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 }
}Billing & Credits
Billed per token: input × input price + output × output price (cache write ×1.25, cache read ×0.1), then × your rate. count_tokens is free. See the Intro page for model prices.