Anthropic-compatible API
Messages, reasoning blocks, and token counting.
POST /v1/messages supports the Anthropic Messages protocol, including system, tools, tool_choice, streaming (SSE), and historical reasoning blocks. All platform models can be called through Messages, for example GLM or DeepSeek in Claude Code. The gateway converts the protocols.
Basic request
curl https://api.goodputai.cn/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $GOODPUT_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "z-ai/glm-5.2",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'You can also use the official Anthropic SDK with base_url="https://api.goodputai.cn".
Thinking blocks
Reasoning models return their reasoning in thinking blocks:
{
"content": [
{"type": "thinking", "thinking": "The user asked…", "signature": ""},
{"type": "text", "text": "ok"}
],
"usage": {"input_tokens": 14, "output_tokens": 30}
}In multi-turn conversations, return historical messages unchanged. The gateway normalizes compatibility issues such as a missing signature in historical thinking blocks; the client need not handle them.
Token counting
Use POST /v1/messages/count_tokens to estimate input tokens before sending a request:
curl https://api.goodputai.cn/v1/messages/count_tokens \
-H "x-api-key: $GOODPUT_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "z-ai/glm-5.2", "messages": [{"role": "user", "content": "hello"}]}'
# => {"input_tokens": 9}Prompt caching
Add cache_control breakpoints to system or message blocks. Confirm a hit with usage.cache_read_input_tokens in the response; those tokens use the cache-read price. See prompt caching for model support.
Tools and web search
- Client tools (
tools+input_schema): see tool calls. - Web search (
web_search_20250305): see web search.