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-Powered PPT Presentations: Complete Guide from Outline to Layout
Creating PPTs with AI tools is as easy as having a conversation. This tutorial teaches you step-by-step how to generate professional presentations in three steps, with tool comparisons and prompt templates for beginners.
TutorialsAI Resume Writing Guide: Generate a Professional Resume in 3 Steps
Learn how to use AI to quickly generate professional resumes for fresh graduates, career changers, and career upgraders. Includes practical prompt templates, beginner-friendly.
TutorialsFamily Meal Planning with AI: Your Smart Assistant for Menu Design & Nutrition
Learn to use AI tools for weekly meal planning — from menu design to nutrition audits and shopping lists. A complete beginner-friendly guide with ready-to-use prompt templates.
Comments are not yet available, stay tuned