default-group token, not a Claude Code-group one.
Choose a model
Use a model whose Endpoints column in the model catalog includes Anthropic Messages, and call it with a token in theClaude Code group. That group carries every Claude-protocol model:
- Claude models: 11 of them, such as
claude-sonnet-5-5andclaude-opus-5-5. See the Anthropic section of the catalog for the full list and prices. - DeepSeek:
deepseek-v4-proanddeepseek-v4-flash. - GLM:
glm-5.2, used in the examples on this page, plusglm-5.3and others. It behaves much like the official Messages API through this protocol. - Kimi:
kimi-k3,kimi-k2.6, and others.
Claude Code group. Call them with a default-group token in the OpenAI-compatible format.
Claude models are available again from October 18, 2026. Read Claude model limits before you switch, and see the announcement for details.
Claude model limits
Claude models support streaming, tool use, adaptive thinking, prompt caching with 5-minute and 1-hour lifetimes, and image input. A few things work differently from Anthropic’s own API:- Output length: each response is capped at 32,768 tokens. A larger
max_tokensis reduced to the cap. - PDFs and documents:
documentcontent blocks are not supported. Extract the text first and send it in atextblock. - Server tools: Anthropic server tools such as
web_search,web_fetch, andcode_executionare not supported, and requests that declare them return 400. - Other endpoints:
/v1/messages/count_tokens, Message Batches, and the Files API are not available. - Stop sequences: when a stop sequence matches,
stop_reasonisend_turnandstop_sequenceisnull. - Long Haiku prompts: when a
claude-haiku-5-5prompt exceeds 100,000 tokens, counting cache reads and writes, the whole request is billed at the long-context rate shown in the catalog’s tiered pricing.
Send a message
Create an API key in Token management in theClaude Code group, with its billing mode set to Usage first (按量优先, recommended) or Usage-based (按量计费), and export it in your terminal:
- cURL
- Python
connected.
The SDK sends the API key and the anthropic-version header for you, and it appends /v1/messages to the base URL, so leave /v1 out of base_url.
System instructions go in the top-level system field, not in a message with a system role.
messages alternates between user and assistant turns; to continue a conversation, send the earlier turns followed by the new user message.
Read the response
This shortened response shows the fields to read:content is a list of blocks, and a reply can contain several of them. Read each block by its type instead of assuming that content[0] is text:
stop_reason explains why the reply ended:
end_turn: the answer is finished.max_tokens: the output limit cut it short.tool_use: the model is waiting for a tool result.
usage; the charge for each request is in call logs.
Stream the response
Add"stream": true to receive the reply as server-sent events.
Text arrives in content_block_delta events whose delta.type is text_delta, and the stream ends with a message_stop event.
- cURL
- Python
-N turns off cURL’s output buffering so that each event prints as soon as it arrives.- Join the
text_deltapieces for each blockindexto rebuild the reply. - Thinking and tool input use other delta types, and a stream can also contain
pingevents, so skip event types you do not handle. - In Python,
text_streamyields only the text and ends aftermessage_stop. - If the connection closes before
message_stop, treat the reply as incomplete.
Use tools
Tools that you define in thetools array run in your application, not on LaoZhang API. When a reply stops with stop_reason: "tool_use":
- Read the
id,name, andinputof eachtool_useblock. - Run the matching function in your code.
- Send the next request with the assistant turn unchanged, followed by a
userturn that holds onetool_resultblock per call. Eachtool_use_idmust match theidof the call it answers.
messages array for that follow-up request looks like this:
tools with every follow-up request, and keep the assistant turn exactly as returned.
Anthropic server tools, such as the web_search_* and code_execution_* tool types, are not executed by the gateway. Claude models reject a request that declares them with a 400 error. Other models return the call as an ordinary tool_use block without running a search or any code. Handle those calls in your application as you would a client tool, or leave these tools out of the request.
Use with Claude Code
Claude Code uses the Anthropic Messages format:- Set
ANTHROPIC_BASE_URLtohttps://api.laozhang.ai(the host root, without/v1). - Choose a model whose Endpoints include Anthropic Messages, such as
claude-sonnet-5-5orglm-5.2. - Use a token in the
Claude Codegroup with the Usage-first billing mode. If Claude Code currently runs on adefault-group token, create a newClaude Code-group token or edit the existing token and change its group.
~/.claude/settings.json, see Claude Code setup with LaoZhang API. If Claude Code returns a 400 ValidationException, see Fix Claude Code 400 ValidationException.
Troubleshooting
- 401: check the
Authorization: Bearerheader and use a model API key from Token management, not an account AccessToken. - 400 that mentions
max_tokens: addmax_tokens. Messages requests require it, unlike Chat Completions. - The request URL contains
/v1/v1/messages: the SDK base URL ends in/v1. Set it tohttps://api.laozhang.ai. - 404 or model not found: check the exact model ID and confirm in the model catalog that it lists Anthropic Messages for your token group.
- 503
Current group claude_code has no available channels for model …: the model isn’t served over the Claude protocol, for example a GPT or Gemini model. Call it with adefault-group token in the OpenAI-compatible format. - 503
Current group default has no available channels for model …:default-group tokens can’t call DeepSeek, GLM, or Kimi over the Claude protocol. Use aClaude Code-group token instead. Claude models aren’t affected. - Claude Code returns
400 ValidationExceptionorExtra inputs are not permitted: follow Fix Claude Code 400 ValidationException errors. - 400 after declaring
web_searchor another server tool on a Claude model: remove the server tool fromtools. Run searches in your application and return the results astool_resultblocks. - 529 with an upstream-busy message: capacity is short at peak times. Retry after a short wait; the Anthropic SDKs retry 529 automatically by default.