Authentication
Authenticate every Yunxin API request with an API key.
API keys
Every request to the Yunxin API is authenticated with an API key. Keys begin with the prefix
sk- and carry the tier, permissions, and balance of the account that created them.
You can send the key in either of two headers — pick whichever your client supports:
X-API-Key: sk-your-key-hereThe Authorization: Bearer form is what the OpenAI and Anthropic SDKs send automatically, so it's the
default for most integrations. X-API-Key is handy for tools and proxies that reserve the
Authorization header for something else.
Creating an API key
- Sign in to your Dashboard. You can register with email & password, or social login via Google, GitHub, Apple, or Discord (additional providers may be enabled per deployment).
- Go to API Keys.
- Click Create API Key and give it a descriptive name (e.g.
production-server,local-dev). - Copy the key immediately — for security, the full key is shown only once. Only a short prefix is stored afterward, so a lost key must be regenerated.
Managing keys
From the Dashboard you can:
- Revoke a key to instantly invalidate a compromised credential.
- Regenerate a key with the same configuration.
- Set a per-key rate limit that is stricter than your tier default.
- Monitor usage per key (see Usage & Monitoring).
Use a separate key per environment and per service. This limits blast radius if one key leaks and makes per-key usage analytics meaningful.
Security best practices
Never embed an API key in client-side code, mobile apps, browser requests, or public repositories. Anyone with the key can spend your balance.
Do
- Store keys in environment variables or a secrets manager.
- Route browser/mobile traffic through your own backend so the key never reaches the client.
- Rotate keys periodically and after any suspected exposure.
- Scope keys per environment and per service.
Don't
- Hardcode keys in source code.
- Commit
.envfiles to version control. - Share keys over chat, email, or other insecure channels.
Example request
curl https://api.yuhuanstudio.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YUNXIN_API_KEY" \
-d '{"model": "model-id", "messages": [{"role": "user", "content": "Hi"}]}'import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com/v1",
)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YUNXIN_API_KEY,
baseURL: "https://api.yuhuanstudio.com/v1",
});Authentication errors
If a key is missing, malformed, or rejected, the API returns a standard error envelope:
| HTTP | code | Meaning |
|---|---|---|
| 401 | authentication_error | No key was provided, or the header was malformed. |
| 401 | invalid_api_key | The key is invalid, expired, or has been revoked. |
| 403 | authorization_error | The key or account lacks permission for this resource. |
| 403 | account_suspended / account_banned | The account is not currently permitted to use the API. |
{
"error": {
"code": "invalid_api_key",
"message": "The provided API key is invalid.",
"request_id": "req_8f3c2a1b"
},
"timestamp": 1709251200
}See Error Handling for the full error model and Rate Limits for throttling behavior.
How is this guide?