# Migration Guide (/docs/migration)


From OpenAI [#from-openai]

Yunxin is fully compatible with the OpenAI API. Migration requires only two changes:

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_YUNXIN_KEY",          # Change API key
    base_url="https://api.yuhuanstudio.com/v1" # Change base URL
)

# All existing code works as-is
response = client.chat.completions.create(
    model="model-id",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

**What works immediately:**

* Chat Completions
* Streaming
* Function calling
* Vision (multimodal)
* Embeddings
* Image generation
* Audio (TTS/STT)
* Video generation
* Music generation
* 3D generation
* Realtime API
* File operations
* Batch API

From Anthropic [#from-anthropic]

Use the Anthropic Messages format directly:

```python
from anthropic import Anthropic

client = Anthropic(
    api_key="YOUR_YUNXIN_KEY",
    base_url="https://api.yuhuanstudio.com/v1"
)

message = client.messages.create(
    model="model-id",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)
```

Or use Anthropic models through the OpenAI-compatible endpoint:

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_YUNXIN_KEY",
    base_url="https://api.yuhuanstudio.com/v1"
)

response = client.chat.completions.create(
    model="model-id",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

From Other Providers [#from-other-providers]

For any provider using OpenAI-compatible API, the migration is the same — change `api_key` and `base_url`.

Environment Variables [#environment-variables]

```bash
# Before (direct OpenAI)
export OPENAI_API_KEY="sk-..."
export OPENAI_BASE_URL="https://api.openai.com/v1"

# After (Yunxin)
export OPENAI_API_KEY="yx-..."
export OPENAI_BASE_URL="https://api.yuhuanstudio.com/v1"
```

Key Benefits After Migration [#key-benefits-after-migration]

| Feature            | Direct Provider          | Yunxin                     |
| ------------------ | ------------------------ | -------------------------- |
| API keys to manage | One per provider         | One for all                |
| Model switching    | Code change per provider | Change model string only   |
| Billing            | Multiple bills           | Unified billing            |
| Monitoring         | Per-provider dashboards  | Single analytics dashboard |
| Failover           | Manual                   | Automatic                  |
