Using OpenAI SDK to seamlessly switch to domestic large models
Why Choose the Compatible Solution?
OpenAI's Python SDK has become the de facto standard for AI development. However, using OpenAI directly faces two issues: network restrictions and model selection.
Ciyuano's compatible solution allows you to freely switch between multiple models without changing a single line of code.
Principle
All requests from the OpenAI SDK are sent to base_url:
# native OpenAI
client = OpenAI(api_key="sk-xxx")
# Ciyuano — Change just two lines!
client = OpenAI(
base_url="https://www.ciyuano.com/v1",
api_key="sk-relay-xxx"
)
The underlying protocols (REST API, SSE streaming, Chat Completions endpoint) are exactly the same.
Hands-on: Multi-Model Comparison Test
from openai import OpenAI
client = OpenAI(
base_url="https://www.ciyuano.com/v1",
api_key="sk-relay-your-key"
)
models = ["deepseek-v4", "glm-5", "qwen-plus"]
prompt = "Using Python Write a quicksort algorithm,with comments"
for model in models:
print(f"n=== {model} ===")
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
max_tokens=1024
)
print(response.choices[0].message.content)
Framework Integration
LangChain
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="deepseek-v4",
openai_api_key="sk-relay-xxx",
openai_api_base="https://www.ciyuano.com/v1"
)
Vercel AI SDK
import { createOpenAI } from "@ai-sdk/openai";
const openai = createOpenAI({
baseURL: "https://www.ciyuano.com/v1",
apiKey: "sk-relay-xxx",
});
Dify / FastGPT / LobeChat
Add an OpenAI-compatible interface in "Model Providers", then fill in Ciyuano's base_url and api_key.
Best Practices
- Use the
automodel: Let the platform automatically select the best available model - Enable streaming output (
stream=True): Better user experience - Set
max_tokensreasonably: Control costs - Choose
qwen-plusif price matters, choosedeepseek-v4if quality matters
Summary
OpenAI SDK + Ciyuano = A unified entry point for any domestic large model. No code changes, no framework swaps, no hassle with keys.
📖 Related Articles
AI 学习助手完整指南:用 AI 高效学习新知识的 5 种方法
手把手教你用 AI 辅助学习:从概念理解、知识梳理到代码学习、笔记整理、自测巩固,5 个实用场景让你的学习效率翻倍。零基础小白也能快速上手。
Tutorials6 Practical Tips for Asking AI Better Questions: Double Your Answer Quality
Many people think AI isn't smart enough, but the real issue is how you ask. This article teaches 6 simple and practical Prompt tips to get more accurate answers from AI.
TutorialsAI Job Search Assistant Guide: Resume Optimization, Cover Letters & Interview Prep
Step-by-step guide to using AI for resume optimization, cover letter writing, and interview prep. From the STAR method to mock interviews, 5 practical scenarios to boost your job search efficiency 10x.
💬 Comments are not yet available, stay tuned