Get started ↗

Integration guide

Anthropic Python SDK and Claude Integration Guide

Call Claude with the Anthropic Python SDK: connect to ZHUAN's /proxy endpoint, use your ZHUAN API key and send requests in Messages format.

Installation and endpoint

Prepare an effective ZHUAN key and set ZHUAN_API_KEY. Use https://key.zhuan.xyz/proxy as the SDK base_url. The SDK appends /v1/messages, so do not repeat the full request path in base_url.

python -m pip install anthropic

A minimal Messages request

max_tokens limits the output for this request, while messages contains the user input. This example uses claude-sonnet-4-6. Confirm it is still in the catalog and check current prices first.

import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["ZHUAN_API_KEY"],
    base_url="https://key.zhuan.xyz/proxy",
    timeout=60.0,
    max_retries=0,
)

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=128,
    messages=[{"role": "user", "content": "Hello"}],
)
for block in message.content:
    if block.type == "text":
        print(block.text)

Streaming Messages

Reuse the client above and read text_stream inside the messages.stream context manager. The example handles text; tool calls require handling structured content blocks separately.

with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=128,
    messages=[{"role": "user", "content": "Hello"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Compatibility and troubleshooting

  • Validate system prompts, caching, tools and multimodal parameters against the current API. Workloads requiring strict instruction following should be checked with your own evaluation set.
  • For 401, check your ZHUAN key and x-api-key header. For 429, reduce concurrency and back off according to the response. Do not mix OpenAI and Messages request fields.
  • After a successful call, check the model, tokens and charge in the console. Retain the request ID for debugging, not the complete key.

Explore more