Using OpenAI SDK to seamlessly switch to domestic large models

·2 min read·199 views
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

  1. Use the auto model: Let the platform automatically select the best available model
  2. Enable streaming output (stream=True): Better user experience
  3. Set max_tokens reasonably: Control costs
  4. Choose qwen-plus if price matters, choose deepseek-v4 if 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.

Comments are not yet available, stay tuned