惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
GbyAI
GbyAI
U
Unit 42
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
D
DataBreaches.Net
N
Netflix TechBlog - Medium
H
Hackread – Cybersecurity News, Data Breaches, AI and More
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
Martin Fowler
Martin Fowler
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
MyScale Blog
MyScale Blog
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
罗磊的独立博客
B
Blog RSS Feed
J
Java Code Geeks
The GitHub Blog
The GitHub Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to use one OpenAI-compatible gateway for chat, respon...
Chinallmapi · 2026-04-29 · via DEV Community

If you're building an AI-powered app today, you're probably juggling multiple model providers. OpenAI for GPT. DeepSeek for cost savings. A Chinese model for specific tasks. Maybe Anthropic for Claude.

Each provider has its own SDK, its own auth flow, its own quirks. That's not just annoying—it's fragile. Switching models means rewriting code. Adding a new provider means more maintenance burden.

There's a cleaner approach: one gateway that speaks OpenAI's protocol, but routes to multiple backends.

This isn't about replacing your provider. It's about abstracting the integration layer so you can swap, compare, and combine models without touching your application code.

Let's walk through what this looks like in practice, using ChinaLLM as a concrete example of a publicly documented gateway.


Why OpenAI-compatible matters more than another SDK

The OpenAI API format has become a de facto standard. Most AI tools—LangChain, AutoGen, custom agents—expect an OpenAI-style interface:

If you switch to another provider, you either:

  • Rewrite your integration code
  • Use a provider-specific SDK (and lock yourself in)
  • Find a gateway that translates everything into the format you already know

The third option is increasingly viable. A gateway that exposes OpenAI-compatible endpoints but routes to multiple backends gives you:

  • Portability: change providers without code changes
  • Comparison: test different models side-by-side with the same API call
  • Cost optimization: route to cheaper models when quality differences don't matter
  • Simpler stack: one auth flow, one SDK, one set of error handling patterns

This isn't theoretical. ChinaLLM, for instance, exposes exactly this kind of gateway—publicly documented, with known endpoints and pricing.


What ChinaLLM publicly exposes today

ChinaLLM is an OpenAI-compatible API gateway that routes to both OpenAI models and China-native providers (DeepSeek, Alibaba coding plans, GLM, ZAI).

Public documentation shows the following endpoints:

Core chat:

  • /v1/chat/completions — standard OpenAI chat format
  • /v1/responses — OpenAI Responses API format
  • /v1/responses/compact — compacted responses for lower token usage
  • /v1/messages — Anthropic-style messages (Claude protocol)

Discovery and embeddings:

  • /v1beta/models — list available models
  • /v1/embeddings — text embeddings
  • /v1/rerank — reranking for search/RAG pipelines

Image:

  • /v1/images/generations — generate images from text
  • /v1/images/edits — edit existing images
  • /v1/images/variations — create variations of an image

Audio:

  • /v1/audio/speech — text-to-speech
  • /v1/audio/transcriptions — speech-to-text
  • /v1/audio/translations — translate audio to English text

All endpoints use OpenAI-compatible request/response formats. The same SDK you use for OpenAI works here—just change the base URL.


Getting a token and setting a base URL

The setup is minimal:

  1. Get an API key from ChinaLLM (signup process is standard)
  2. Set your base URL to https://chinallmapi.com/v1
  3. Use your existing OpenAI SDK or HTTP client

No new dependencies. No new auth patterns.

For complete code examples, see the GitHub repo.

Example with OpenAI Python SDK:

import openai

client = openai.OpenAI(
    api_key="your-chinallm-key",
    base_url="https://chinallmapi.com/v1"
)

# Now use it exactly like you would with OpenAI
response = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "What's the capital of France?"}]
)

print(response.choices[0].message.content)

Enter fullscreen mode Exit fullscreen mode

Same SDK. Same method signatures. Different backend.


First request with /v1/chat/completions

Let's make a real request. We'll use a cost-efficient model from the public pricing list: deepseek-v4-flash.

import openai

client = openai.OpenAI(
    api_key="your-chinallm-key",
    base_url="https://chinallmapi.com/v1"
)

response = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[
        {"role": "system", "content": "You are a helpful coding assistant."},
        {"role": "user", "content": "Write a Python function to merge two sorted lists."}
    ],
    temperature=0.7
)

print(response.choices[0].message.content)

Enter fullscreen mode Exit fullscreen mode

This returns a response in standard OpenAI format.

The key insight: you didn't change any code to switch from OpenAI to DeepSeek. You just changed the model name.


Expanding beyond chat (responses / embeddings / rerank)

Chat is the obvious use case. But a unified gateway becomes more valuable when you need multiple capabilities in the same app.

Responses API

The Responses API (/v1/responses) is useful when you want structured outputs with built-in reasoning traces:

response = client.responses.create(
    model="gpt-5.4",
    input="Analyze this customer feedback and extract sentiment, topic, and action items.",
    instructions="Return a JSON object with sentiment, topic, and action_items fields."
)

print(response.output)

Enter fullscreen mode Exit fullscreen mode

Embeddings

For RAG or semantic search:

embedding = client.embeddings.create(
    model="text-embedding-3-small",
    input="What are the best practices for API design?"
)

vector = embedding.data[0].embedding
print(f"Embedding dimension: {len(vector)}")

Enter fullscreen mode Exit fullscreen mode

Rerank

When you have multiple candidate documents and need to rank them by relevance to a query:

import requests

response = requests.post(
    "https://chinallmapi.com/v1/rerank",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
        "model": "rerank-model",
        "query": "What is the refund policy?",
        "documents": [
            "Our refund policy allows returns within 30 days...",
            "Shipping takes 5-7 business days...",
            "We accept PayPal and credit cards..."
        ]
    }
)

print(response.json()["results"])

Enter fullscreen mode Exit fullscreen mode

Each capability uses the same auth pattern, same base URL, familiar request formats. No separate SDKs for embeddings vs. chat vs. rerank.


Public pricing and model discovery

ChinaLLM's pricing page shows transparent model costs with group-specific multipliers:

Group multipliers:

  • CodingPlan (Alibaba coding plans): 1.1x
  • DeepSeek: 1.05x
  • GLM: 1.05x
  • OpenAI: 1.3x

This means:

  • DeepSeek models cost roughly 5% more than base DeepSeek pricing
  • OpenAI models cost roughly 30% more than base OpenAI pricing
  • The gateway adds a margin, but you get unified access and simpler integration

Visible models (partial list from public docs):

  • gpt-5.4, gpt-5.5 (OpenAI)
  • gpt-image-2 (OpenAI image model)
  • deepseek-v4-flash, deepseek-v4-pro (DeepSeek)
  • glm-4.7 (GLM/Zhipu)

To discover all available models:

models = client.models.list()
for model in models.data:
    print(model.id)

Enter fullscreen mode Exit fullscreen mode

This returns the current model catalog—useful when new models are added without announcement.


When this approach is useful

A unified gateway isn't for everyone. But it's particularly valuable when:

  1. You're comparing models. You want to test GPT vs. DeepSeek vs. GLM on the same task without rewriting integration code.

  2. You're optimizing costs. You want to route simple queries to cheaper models and complex ones to premium models—all through one API.

  3. You're building multi-modal apps. You need chat + embeddings + images + audio in one stack, and don't want separate auth flows for each.

  4. You're building tooling. You want your framework to support multiple providers out of the box, without hardcoding provider-specific logic.

  5. You're hedging provider risk. You want the option to switch providers quickly if pricing changes, service quality drops, or better options emerge.

The gateway approach abstracts away provider differences. You still need to know which model to use for which task—but you don't need separate code for each provider.


Final takeaway

One OpenAI-compatible gateway. Multiple backends. Same SDK. Same auth. Same request formats.

This isn't about replacing your provider. It's about making your integration layer more portable, more testable, and more resilient to provider changes.

ChinaLLM is one concrete implementation of this pattern—publicly documented, with transparent pricing and a clear model catalog. If you're evaluating this approach, it's a useful reference point.

The bigger idea: stop writing provider-specific integration code. Write to a standard interface, and let the gateway handle the routing.