# Claude Code (/docs/examples/claude-code)


Overview [#overview]

[Claude Code](https://docs.anthropic.com/en/docs/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 [#prerequisites]

* [Claude Code](https://docs.anthropic.com/en/docs/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 [#configuration]

Claude Code can be configured to use Yunxin as a custom API provider. Set the following environment variables:

```bash
export ANTHROPIC_API_KEY="YOUR_YUNXIN_API_KEY"
export ANTHROPIC_BASE_URL="https://api.yuhuanstudio.com/v1"
```

<Callout type="info">
  Claude Code uses the Anthropic Messages API format. Yunxin supports the `/v1/messages` endpoint, which is fully compatible with Claude Code's expectations.
</Callout>

Alternatively, create a `.env` file in your project root:

```bash
ANTHROPIC_API_KEY=your-yunxin-api-key
ANTHROPIC_BASE_URL=https://api.yuhuanstudio.com/v1
```

Usage [#usage]

Start a Session [#start-a-session]

Launch Claude Code in your project directory:

```bash
cd your-project
claude
```

Claude Code will connect to Yunxin's API and use whichever model you have configured.

Specify a Model [#specify-a-model]

You can specify which model to use through Claude Code's model selection:

```bash
claude --model model-id
```

Or set it persistently:

```bash
export ANTHROPIC_MODEL="model-id"
```

Example Session [#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 [#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 [#recommended-models]

For the best Claude Code experience, use models with strong coding capabilities:

```bash
# Query available models
curl https://api.yuhuanstudio.com/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"
```

<Callout type="info">
  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.
</Callout>

Troubleshooting [#troubleshooting]

Connection Errors [#connection-errors]

If Claude Code cannot connect:

1. Verify your API key is correct
2. Check that `ANTHROPIC_BASE_URL` is set to `https://api.yuhuanstudio.com/v1`
3. Ensure your Yunxin account has active quota

Rate Limiting [#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 [#resources]

* [Claude Code Documentation](https://docs.anthropic.com/en/docs/claude-code)
* [Yunxin API Reference](/docs/chat-completions)
* [Authentication Guide](/docs/authentication)
