SDKs & Libraries
Use the Yunxin API with the OpenAI and Anthropic SDKs — no custom client required.
No custom SDK needed
Yunxin speaks the OpenAI and Anthropic wire formats natively. To integrate, point an existing SDK at
the Yunxin base URL and use your sk- API key:
https://api.yuhuanstudio.com/v1
- Use the OpenAI SDK for Chat Completions and the Responses API.
- Use the Anthropic SDK for the Messages API.
- Or call the endpoints directly over HTTP.
OpenAI SDK
pip install openaiimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com/v1",
)
response = client.chat.completions.create(
model="model-id",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)npm install openaiimport OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YUNXIN_API_KEY,
baseURL: "https://api.yuhuanstudio.com/v1",
});
const response = await client.chat.completions.create({
model: "model-id",
messages: [{ role: "user", content: "Hello!" }],
});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": "Hello!"}]}'Anthropic SDK
For the native Anthropic message format, point the Anthropic SDK at the same base URL:
import os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com",
)
message = client.messages.create(
model="model-id",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)The Anthropic SDK appends /v1/messages itself, so set base_url to the host
(https://api.yuhuanstudio.com) without the /v1 suffix. The OpenAI SDK, by contrast, expects the
/v1 suffix on base_url.
Environment variables
Keep credentials out of source code:
export YUNXIN_API_KEY="sk-your-key-here"
export YUNXIN_BASE_URL="https://api.yuhuanstudio.com/v1"import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url=os.environ.get("YUNXIN_BASE_URL", "https://api.yuhuanstudio.com/v1"),
)Both Authorization: Bearer sk-... and X-API-Key: sk-... are accepted if you call the API directly.
See Authentication.
How is this guide?