cd /news/artificial-intelligence/building-a-unified-openai-compatible… · home topics artificial-intelligence article
[ARTICLE · art-79689] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

Building a unified OpenAI-compatible gateway for 16 Chinese LLMs: architecture notes on routing, payments and ops

A developer built HOUJIAYAN API, an OpenAI-compatible gateway that routes requests across 16 Chinese LLMs including DeepSeek, Kimi, Qwen, MiniMax, and Doubao. The gateway handles authentication, billing, and automatic routing with three tiers (quality, balanced, cost), and supports WeChat Pay and USDT-TRC20 payments. The developer noted that WeChat's new 'platform public key' mode causes callback signature verification failures for new merchant accounts.

read3 min views1 publishedJul 30, 2026

Why we built this

If you want to use Chinese frontier models — DeepSeek, Kimi, Qwen, MiniMax, Doubao — as an international developer, you quickly hit friction: every provider has its own auth scheme, its own billing quirks, and several require mainland-China payment methods or business verification. We run these models in production ourselves, so we built the gateway we wanted to have: one OpenAI-compatible endpoint, one API key, and automatic routing across 16 Chinese LLMs.

The result is HOUJIAYAN API (https://api.houjiayan.com). These are our architecture notes.

Architecture

Client (any OpenAI SDK)
   │  https://api.houjiayan.com/v1
   ▼
Cloudflare (WAF / rate limiting / TLS)
   ▼
NewAPI (forked) — channels, API keys, quota, billing
   │        │
   ▼        ▼
Custom smart    Custom payment bridge (standalone service)
router          ├─ WeChat Native Pay (APIv3)
(quality /      └─ NOWPayments (USDT-TRC20)
 balanced /
 cost tiers)
   │
   ▼
16 upstream model channels (11 enrolled in auto-routing)

Gateway: a fork of NewAPI.NewAPI is a mature open-source API gateway popular in the Chinese LLM ecosystem. We kept its channel abstraction, token management and quota accounting, and customized pricing so that rates stay exactly at upstream official pricing — no markup — with a live price table in the console. Rates go as low as ¥1.00 / 1M tokens.

Smart router: a custom stateless service.Beyond the standard `/v1/chat/completions` (where you can pin any of the 16 models directly), we expose `POST /v1/auto/chat/completions` with three routing tiers:

- `quality` (default): pick the highest-quality model for the task class;
- `balanced`: the quality/cost sweet spot;
- `cost`: cheapest adequate model, for batch workloads.

The router scores candidate channels by task features (context length, code vs. prose, expected output length) against a curated quality-tier table. Fourteen of the sixteen models participate in the auto pool. On upstream failure it degrades to the next-best channel.

Payment bridge: the hardest part.NewAPI doesn't handle payments, so we built a standalone pay\_bridge service:

- WeChat Native Pay APIv3 for domestic users (QR-code Native orders → signed callback → signed epay-style notify into the gateway);
- NOWPayments for USDT-TRC20 for users outside mainland China (IPN callback → FX conversion → credit).

The bridge talks to the gateway through a signed callback protocol so the gateway credits accounts natively — no double-entry writes.

Lessons learned

1. WeChat's new "platform public key" mode.New merchant accounts are forced onto public-key verification (key IDs prefixed with `PUB_KEY_ID_`) instead of the old platform-certificate chain. Nearly all tutorials and SDK examples still assume certificate mode. If your callback signature verification fails on a new merchant account, this is why.
2. `base_url` must end with `/v1`.The OpenAI SDK concatenates paths onto `base_url`, so `https://api.houjiayan.com` alone 404s. We added a gentle redirect at the edge, and put the correct snippet at the top of the docs:

python

from openai import OpenAI

client = OpenAI(api_key="sk-...", base_url="https://api.houjiayan.com/v1")

3. Usage accounting across providers.Upstreams report token usage inconsistently (some only at the end of a stream). We normalize accounting to gateway-parsed usage with a local estimation fallback for streams that never report it, and keep per-request audit detail.

Access & pricing (full disclosure)

- Endpoint: `https://api.houjiayan.com/v1` (OpenAI-compatible); auto-routing at `POST /v1/auto/chat/completions`
- Models: 16 Chinese LLMs directly addressable (DeepSeek V4 Pro/Flash, Kimi K3, MiniMax M3, Qwen3.6/3.7 series, Doubao Seed Code, etc.); 11 in the auto-routing pool
- Pricing: identical to upstream official pricing, no markup; live table in the console; from ¥1.00 / 1M tokens
- Sign-up credit: ¥6.6 (~$1) free trial credit; stays valid with ongoing usage; reclaimed only after 7 consecutive days with no API calls and no logins
- Top-up: WeChat Pay (min ¥50, 5.5% service fee); USDT-TRC20 (min $25, 5% service fee, non-mainland-China residents only)
- Refunds: WeChat top-ups refundable within 24h if unused (service fee excluded); crypto top-ups are non-refundable
- Docs: https://houjiayan.com/docs/
- Operator: Inner Mongolia Huozhong Intelligent Technology Co., Ltd.; support@houjiayan.com

What's next

Routing tiers are currently static + task-feature scoring. We plan to fold historical success rate, latency and user feedback into dynamic channel weights.Support more models and payment methods. Happy to compare notes with anyone running multi-upstream LLM gateways.

---
── more in #artificial-intelligence 4 stories · sorted by recency
── more on @deepseek 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/building-a-unified-o…] indexed:0 read:3min 2026-07-30 ·