Skip to main content
The Claude protocol is Anthropic’s Messages API format. Anthropic SDKs and Claude Code connect once you change the base URL and use your LaoZhang API key.
If your application uses the OpenAI SDK, use the OpenAI protocol instead; the models listed below accept both formats. The two formats use different request and response structures, so pick one per client. OpenAI-format requests need a 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 the Claude Code group. That group carries every Claude-protocol model:
  • Claude models: 11 of them, such as claude-sonnet-5-5 and claude-opus-5-5. See the Anthropic section of the catalog for the full list and prices.
  • DeepSeek: deepseek-v4-pro and deepseek-v4-flash.
  • GLM: glm-5.2, used in the examples on this page, plus glm-5.3 and others. It behaves much like the official Messages API through this protocol.
  • Kimi: kimi-k3, kimi-k2.6, and others.
GPT, Gemini, Qwen, MiniMax, and image and video models are not in the 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.
Copy model IDs exactly from the catalog or the console pricing page rather than building them from a product name or a Bedrock or Vertex AI ID.

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_tokens is reduced to the cap.
  • PDFs and documents: document content blocks are not supported. Extract the text first and send it in a text block.
  • Server tools: Anthropic server tools such as web_search, web_fetch, and code_execution are 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_reason is end_turn and stop_sequence is null.
  • Long Haiku prompts: when a claude-haiku-5-5 prompt 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 the Claude Code group, with its billing mode set to Usage first (按量优先, recommended) or Usage-based (按量计费), and export it in your terminal:
The reply should be 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.
Token counts are in 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.
-N turns off cURL’s output buffering so that each event prints as soon as it arrives.
A streamed reply follows this sequence, shortened here to the fields you need:
When you read the stream:
  • Join the text_delta pieces for each block index to rebuild the reply.
  • Thinking and tool input use other delta types, and a stream can also contain ping events, so skip event types you do not handle.
  • In Python, text_stream yields only the text and ends after message_stop.
  • If the connection closes before message_stop, treat the reply as incomplete.

Use tools

Tools that you define in the tools array run in your application, not on LaoZhang API. When a reply stops with stop_reason: "tool_use":
  1. Read the id, name, and input of each tool_use block.
  2. Run the matching function in your code.
  3. Send the next request with the assistant turn unchanged, followed by a user turn that holds one tool_result block per call. Each tool_use_id must match the id of the call it answers.
The messages array for that follow-up request looks like this:
This loop runs the whole exchange with the Python SDK. It declares a weather function, runs it locally when the model asks, and sends the result back until the model answers in text:
Send the same 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_URL to https://api.laozhang.ai (the host root, without /v1).
  • Choose a model whose Endpoints include Anthropic Messages, such as claude-sonnet-5-5 or glm-5.2.
  • Use a token in the Claude Code group with the Usage-first billing mode. If Claude Code currently runs on a default-group token, create a new Claude Code-group token or edit the existing token and change its group.
For a complete ~/.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: Bearer header and use a model API key from Token management, not an account AccessToken.
  • 400 that mentions max_tokens: add max_tokens. Messages requests require it, unlike Chat Completions.
  • The request URL contains /v1/v1/messages: the SDK base URL ends in /v1. Set it to https://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 a default-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 a Claude Code-group token instead. Claude models aren’t affected.
  • Claude Code returns 400 ValidationException or Extra inputs are not permitted: follow Fix Claude Code 400 ValidationException errors.
  • 400 after declaring web_search or another server tool on a Claude model: remove the server tool from tools. Run searches in your application and return the results as tool_result blocks.
  • 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.
For a timeout or a 5xx error, check call logs before sending the request again. The Python examples disable automatic retries so that your application decides when to retry.