Claude Code
Use Yunxin as the backend for Claude Code via the Anthropic Messages API.
Overview
Claude Code is Anthropic's official coding CLI. It
talks to an Anthropic-compatible Messages endpoint, which Yunxin implements natively at
POST /v1/messages — so you can point Claude Code at Yunxin and use any model Yunxin routes to.
Prerequisites
- Claude Code installed:
npm install -g @anthropic-ai/claude-code - A Yunxin API key from Dashboard → API Keys (keys begin with
sk-) - A model id that supports chat/messages — discover ids via the Models API
Configuration
Claude Code reads its endpoint and key from environment variables. Set the base URL to
https://api.yuhuanstudio.com without a /v1 suffix — the Anthropic client appends /v1/messages itself.
export ANTHROPIC_BASE_URL="https://api.yuhuanstudio.com"
export ANTHROPIC_API_KEY="sk-your-yunxin-key"Don't add /v1 to ANTHROPIC_BASE_URL. Anthropic-style clients build the full path themselves, so the
base URL is https://api.yuhuanstudio.com (not .../v1). Adding /v1 would produce
/v1/v1/messages and fail.
Yunxin authenticates the same sk- key sent either as Authorization: Bearer or X-API-Key; Claude
Code uses the Anthropic header convention automatically. See Authentication.
Alternatively, place these in a .env file your shell loads:
ANTHROPIC_BASE_URL=https://api.yuhuanstudio.com
ANTHROPIC_API_KEY=sk-your-yunxin-keyUsage
Start a session
cd your-project
claudeClaude Code connects to Yunxin's /v1/messages endpoint and streams responses into your terminal.
Specify a model
claude --model model-idOr set it persistently:
export ANTHROPIC_MODEL="model-id"Use a provider/model id (for example anthropic/claude-...) to pin a specific provider, or a plain
id to let Yunxin route.
Supported features
Claude Code drives the Messages API, including streaming and tool use, which Yunxin supports:
| Feature | Supported | Notes |
|---|---|---|
| Messages API | Yes | Via POST /v1/messages. |
| Streaming | Yes | SSE token streaming (message_start … message_stop). |
| Multi-turn conversations | Yes | Full conversation context. |
| Tool use / file edits | Yes | Claude Code's read/edit tools rely on tool use. |
| Vision | Yes | With multimodal models. |
| Extended thinking | Model-dependent | Available on models that expose a thinking capability. |
Feature availability ultimately depends on the model you choose — check each model's capabilities
array via the Models API.
Recommended models
For coding, prefer models with strong reasoning and tool-use capabilities. List what's available:
curl https://api.yuhuanstudio.com/v1/models \
-H "Authorization: Bearer $YUNXIN_API_KEY"The catalog is discovered at runtime and changes without redeploys, so query /v1/models (or the
Dashboard) rather than relying on a fixed list.
Troubleshooting
Connection errors
- Verify
ANTHROPIC_BASE_URLis exactlyhttps://api.yuhuanstudio.com(no/v1). - Verify your
sk-key is valid and not revoked. - Confirm your account has sufficient credit balance — a
402 insufficient_balancemeans top up.
Rate limiting
Yunxin enforces a per-minute request limit by tier (Free 10, Basic 50, Fellow/Pro 100, Enterprise
custom). On 429, honor the Retry-After header. Watch X-RateLimit-Remaining to pace requests. See
Rate Limits.
Resources
How is this guide?