Claude Code
Use Claude Code with the Yunxin API as a custom provider.
Overview
Claude Code is Anthropic's official CLI tool that brings AI-powered coding assistance directly to your terminal. It supports connecting to custom OpenAI-compatible API endpoints, making it fully compatible with Yunxin.
Prerequisites
- Claude Code installed (via
npm install -g @anthropic-ai/claude-code) - A Yunxin API key from Dashboard → API Keys
- At least one model configured in Yunxin that supports chat completions
Configuration
Claude Code can be configured to use Yunxin as a custom API provider. Set the following environment variables:
export ANTHROPIC_API_KEY="YOUR_YUNXIN_API_KEY"
export ANTHROPIC_BASE_URL="https://api.yuhuanstudio.com/v1"Claude Code uses the Anthropic Messages API format. Yunxin supports the /v1/messages endpoint, which is fully compatible with Claude Code's expectations.
Alternatively, create a .env file in your project root:
ANTHROPIC_API_KEY=your-yunxin-api-key
ANTHROPIC_BASE_URL=https://api.yuhuanstudio.com/v1Usage
Start a Session
Launch Claude Code in your project directory:
cd your-project
claudeClaude Code will connect to Yunxin's API and use whichever model you have configured.
Specify a Model
You can specify which model to use through Claude Code's model selection:
claude --model model-idOr set it persistently:
export ANTHROPIC_MODEL="model-id"Example Session
> How do I implement JWT authentication in Express?
Claude Code will send this request to Yunxin's /v1/messages endpoint
and stream the response back to your terminal with code suggestions.Supported Features
When using Claude Code with Yunxin, the following features work seamlessly:
| Feature | Supported | Notes |
|---|---|---|
| Chat Completions | Yes | Via /v1/messages endpoint |
| Streaming | Yes | Real-time token streaming |
| Multi-turn Conversations | Yes | Full conversation context |
| Code Generation | Yes | Syntax-highlighted output |
| File Operations | Yes | Read and edit files via tool use |
| Vision | Yes | Image analysis via multimodal models |
| Function Calling | Yes | Tool use capabilities |
Recommended Models
For the best Claude Code experience, use models with strong coding capabilities:
# Query available models
curl https://api.yuhuanstudio.com/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"Check the Yunxin dashboard for a full list of available models. Models with strong coding and reasoning capabilities provide the best results with Claude Code.
Troubleshooting
Connection Errors
If Claude Code cannot connect:
- Verify your API key is correct
- Check that
ANTHROPIC_BASE_URLis set tohttps://api.yuhuanstudio.com/v1 - Ensure your Yunxin account has active quota
Rate Limiting
Yunxin enforces rate limits based on your tier. If you encounter rate limit errors:
- Free tier: 10 requests/minute
- Basic tier: 50 requests/minute
- Pro tier: 100 requests/minute
- Enterprise tier: Unlimited
Check the X-RateLimit-Remaining response header to monitor your usage.
Resources
How is this guide?