Martin-hhht

為什麼我們要建置這個

如果你想使用中國前沿模型——DeepSeek、Kimi、Qwen、MiniMax、Doubao——身為國際開發者,你很快就會遇到摩擦:每個供應商都有自己的驗證方式、自己的計費特性,而且其中幾家還要求中國大陸的付款方式或企業驗證。我們自己也在生產環境中使用這些模型,因此我們打造了我們希望擁有的閘道:一個與 OpenAI 相容的端點、一把 API 金鑰,以及跨 16 個中國 LLM 的自動路由。

成果就是 HOUJIAYAN API (https://api.houjiayan.com)。以下是我們的架構筆記。

架構

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:

Enter fullscreen mode Exit fullscreen mode


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.; [email protected]

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.

---

Enter fullscreen mode Exit fullscreen mode