Skip to content

Commit b718596

Browse files
dbclaude
andcommitted
feat(bailian): add native support for Alibaba Cloud Bailian (百炼)
Add Bailian provider with: - Chat completions translation (max_tokens → max_completion_tokens) - Full Passthrough router support - Streaming and non-streaming responses - Configurable base URL for region switching Merge upstream/main (Xiaomi MiMo provider, cache logging fixes). Add local pre-commit lint hook (git config core.hooksPath .githooks). Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 414b491 commit b718596

11 files changed

Lines changed: 1098 additions & 2 deletions

File tree

.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@
352352
# Set base URL to enable (default: http://localhost:11434/v1)
353353
# OLLAMA_BASE_URL=http://localhost:11434/v1
354354

355+
# Alibaba Cloud Bailian (百炼)
356+
# BAILIAN_API_KEY=...
357+
# BAILIAN_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
358+
355359
# vLLM (OpenAI-compatible server)
356360
# VLLM_API_KEY is optional; set it only if vllm serve was started with --api-key.
357361
# VLLM_API_KEY=token-abc123

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
# Local git worktrees
2727
/.worktrees/
2828

29+
# Local pre-commit hook (not shared)
30+
/.githooks/
31+
2932
# Others
3033
/*.bck.yml
3134
/repomix-output.*
3235
/coverage.out
3336
/.claude/
37+
38+
# Superpower design docs and plans (never commit)
39+
/docs/superpowers/

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ Full reference: `.env.template` and `config/config.yaml`
128128
- **Resilience:** Configured via `config/config.yaml` - global `resilience.retry.*` and `resilience.circuit_breaker.*` defaults with optional per-provider overrides under `providers.<name>.resilience.retry.*` and `providers.<name>.resilience.circuit_breaker.*`. Retry defaults: `max_retries` (3), `initial_backoff` (1s), `max_backoff` (30s), `backoff_factor` (2.0), `jitter_factor` (0.1). Circuit breaker defaults: `failure_threshold` (5), `success_threshold` (2), `timeout` (30s)
129129
- **Metrics:** `METRICS_ENABLED` (false), `METRICS_ENDPOINT` (/metrics)
130130
- **Guardrails:** Configured via `config/config.yaml` only (except `GUARDRAILS_ENABLED` env var)
131-
- **Providers:** `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, `USE_GOOGLE_GEMINI_NATIVE_API` (true by default; false uses Gemini's OpenAI-compatible chat API), `XAI_API_KEY`, `GROQ_API_KEY`, `OPENROUTER_API_KEY`, `ZAI_API_KEY`, `ZAI_BASE_URL` (optional Z.ai endpoint override), `MINIMAX_API_KEY`, `MINIMAX_BASE_URL` (optional MiniMax endpoint override), `XIAOMI_API_KEY`, `XIAOMI_BASE_URL` (optional Xiaomi MiMo endpoint override), `AZURE_API_KEY`, `AZURE_BASE_URL` (Azure OpenAI deployment base URL), `AZURE_API_VERSION` (optional Azure API version), `ORACLE_API_KEY` (Oracle API key), `ORACLE_BASE_URL` (Oracle OpenAI-compatible base URL), `<PROVIDER>[_SUFFIX]_MODELS` (comma-separated configured model list for any provider type), `OLLAMA_BASE_URL`, `VLLM_BASE_URL`, `VLLM_API_KEY` (optional upstream vLLM bearer token)
131+
- **Providers:** `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, `USE_GOOGLE_GEMINI_NATIVE_API` (true by default; false uses Gemini's OpenAI-compatible chat API), `XAI_API_KEY`, `GROQ_API_KEY`, `OPENROUTER_API_KEY`, `ZAI_API_KEY`, `ZAI_BASE_URL` (optional Z.ai endpoint override), `MINIMAX_API_KEY`, `MINIMAX_BASE_URL` (optional MiniMax endpoint override), `XIAOMI_API_KEY`, `XIAOMI_BASE_URL` (optional Xiaomi MiMo endpoint override), `BAILIAN_API_KEY`, `BAILIAN_BASE_URL` (optional Bailian base URL for region switching; default `https://dashscope.aliyuncs.com/compatible-mode/v1`), `AZURE_API_KEY`, `AZURE_BASE_URL` (Azure OpenAI deployment base URL), `AZURE_API_VERSION` (optional Azure API version), `ORACLE_API_KEY` (Oracle API key), `ORACLE_BASE_URL` (Oracle OpenAI-compatible base URL), `<PROVIDER>[_SUFFIX]_MODELS` (comma-separated configured model list for any provider type), `OLLAMA_BASE_URL`, `VLLM_BASE_URL`, `VLLM_API_KEY` (optional upstream vLLM bearer token)
132132
- **Provider model metadata:** `providers.<name>.models` accepts either model IDs (strings) or `{id, metadata}` objects. When `metadata` is supplied (`display_name`, `context_window`, `max_output_tokens`, `modes`, `capabilities`, `pricing`, …) it is merged onto the remote ai-model-list entry during enrichment, with operator values winning per-field. Primary use case: advertising context windows, capabilities, and pricing for local models (Ollama) and other custom endpoints whose IDs are not in the upstream registry.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Example model identifiers are illustrative and subject to change; consult provid
100100
| OpenRouter | `OPENROUTER_API_KEY` | `google/gemini-2.5-flash` |||||||
101101
| Z.ai | `ZAI_API_KEY` (`ZAI_BASE_URL` optional) | `glm-5.1` |||||||
102102
| xAI (Grok) | `XAI_API_KEY` | `grok-4` |||||||
103+
| Alibaba Cloud Bailian | `BAILIAN_API_KEY` (`BAILIAN_BASE_URL` optional) | `qwen3-max` |||||||
103104
| MiniMax | `MINIMAX_API_KEY` (`MINIMAX_BASE_URL` optional) | `MiniMax-M3` |||||||
104105
| Xiaomi MiMo | `XIAOMI_API_KEY` (`XIAOMI_BASE_URL` optional) | `mimo-v2.5-pro` |||||||
105106
| Azure OpenAI | `AZURE_API_KEY` + `AZURE_BASE_URL` (`AZURE_API_VERSION` optional) | `gpt-5` |||||||

cmd/gomodel/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"gomodel/internal/providers"
1919
"gomodel/internal/providers/anthropic"
2020
"gomodel/internal/providers/azure"
21+
"gomodel/internal/providers/bailian"
2122
"gomodel/internal/providers/bedrock"
2223
"gomodel/internal/providers/deepseek"
2324
"gomodel/internal/providers/gemini"
@@ -76,7 +77,7 @@ func startApplication(application lifecycleApp, addr string) error {
7677

7778
// @title GoModel API
7879
// @version 1.0
79-
// @description AI gateway routing requests to multiple LLM providers (OpenAI, Anthropic, Gemini, Groq, OpenRouter, DeepSeek, Z.ai, xAI, MiniMax, Xiaomi MiMo, Oracle, Ollama). Drop-in OpenAI-compatible API.
80+
// @description AI gateway routing requests to multiple LLM providers (OpenAI, Anthropic, Gemini, Groq, OpenRouter, DeepSeek, Z.ai, xAI, MiniMax, Xiaomi MiMo, Oracle, Ollama, Bailian). Drop-in OpenAI-compatible API.
8081
// @BasePath /
8182
// @schemes http
8283
// @securityDefinitions.apikey BearerAuth
@@ -120,6 +121,7 @@ func main() {
120121
factory.Add(openai.Registration)
121122
factory.Add(openrouter.Registration)
122123
factory.Add(azure.Registration)
124+
factory.Add(bailian.Registration)
123125
factory.Add(oracle.Registration)
124126
factory.Add(anthropic.Registration)
125127
factory.Add(bedrock.Registration)

config/config.example.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ providers:
199199
type: anthropic
200200
api_key: "sk-ant-..."
201201

202+
bailian:
203+
type: bailian
204+
api_key: "${BAILIAN_API_KEY}"
205+
# Base URL for Alibaba Cloud Bailian (DashScope).
206+
# Default: Beijing - "https://dashscope.aliyuncs.com/compatible-mode/v1"
207+
# Singapore: "https://{workspace-id}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
208+
# Frankfurt: "https://{workspace-id}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1"
209+
# Hong Kong: "https://{workspace-id}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1"
210+
202211
gemini:
203212
type: gemini
204213
api_key: "..."

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"providers/anthropic",
105105
"providers/gemini",
106106
"providers/deepseek",
107+
"providers/bailian",
107108
"providers/xiaomi",
108109
"providers/vllm",
109110
"providers/multiple-ollama",

docs/providers/bailian.mdx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: "Alibaba Cloud Bailian"
3+
description: "Configure Alibaba Cloud Bailian (百炼 / DashScope) in GoModel, including the max_tokens compatibility shim for models like Qwen."
4+
icon: "cloud"
5+
---
6+
7+
Bailian (百炼) is Alibaba Cloud's model-as-a-service platform for the Qwen
8+
family of models. GoModel routes to Bailian through its OpenAI-compatible
9+
endpoint (`/compatible-mode/v1`).
10+
11+
Because Bailian deprecated `max_tokens` in April 2026 in favor of
12+
`max_completion_tokens`, GoModel automatically maps the standard
13+
`max_tokens` field to `max_completion_tokens` for every request — no
14+
client change required.
15+
16+
## Configure
17+
18+
```bash
19+
BAILIAN_API_KEY=...
20+
```
21+
22+
Or in `config.yaml`:
23+
24+
```yaml
25+
providers:
26+
bailian:
27+
type: bailian
28+
api_key: "${BAILIAN_API_KEY}"
29+
# base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
30+
```
31+
32+
## Base URLs
33+
34+
Bailian's OpenAI-compatible API is available in multiple regions. Set
35+
`BAILIAN_BASE_URL` to switch:
36+
37+
| Region | URL |
38+
| ------ | --- |
39+
| Beijing (default) | `https://dashscope.aliyuncs.com/compatible-mode/v1` |
40+
| Singapore | `https://{workspace-id}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1` |
41+
| Frankfurt | `https://{workspace-id}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1` |
42+
| Hong Kong | `https://{workspace-id}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1` |
43+
44+
## Model IDs
45+
46+
Common Qwen model identifiers — check the [Bailian model
47+
list](https://www.alibabacloud.com/help/zh/model-studio/model-list) for the
48+
current catalog:
49+
50+
| Model | Example ID |
51+
| ----- | ---------- |
52+
| Qwen 3.7 Max | `qwen3.7-max` |
53+
| Qwen 3.7 Plus | `qwen3.7-plus` |
54+
| Qwen 3.6 Flash | `qwen3.6-flash` |
55+
| Qwen 3 Max | `qwen3-max` |
56+
| Qwen 3 Plus | `qwen3-plus` |
57+
| Qwen 3 Flash | `qwen3-flash` |
58+
| Qwen 3 Coder Plus | `qwen3-coder-plus` |
59+
| Text Embedding | `text-embedding-v3` |
60+
61+
## `max_tokens` compatibility
62+
63+
Bailian deprecated `max_tokens` on 2026-04-20 (effective 2026-05-30).
64+
All Bailian models now require `max_completion_tokens` instead.
65+
66+
GoModel transparently maps the standard `max_tokens` parameter to
67+
`max_completion_tokens` for every bailian model — send `max_tokens` as you
68+
normally would, and GoModel rewrites it before forwarding to Bailian.
69+
70+
```bash
71+
# max_tokens=4096 is automatically sent as max_completion_tokens=4096
72+
curl http://localhost:8080/v1/chat/completions \
73+
-H "Content-Type: application/json" \
74+
-d '{
75+
"model": "qwen3-max",
76+
"messages": [{"role": "user", "content": "Hello"}],
77+
"max_tokens": 4096
78+
}'
79+
```
80+
81+
## Supported features
82+
83+
| Feature | Supported |
84+
| ------- | :-------: |
85+
| Chat completions ||
86+
| Streaming chat ||
87+
| Responses (`/v1/responses`) | ✅ (translated to chat) |
88+
| Embeddings | ✅ (configure model IDs via `BAILIAN_MODELS`) |
89+
| Files (`/v1/files`) ||
90+
| Batches (`/v1/batches`) ||
91+
| Passthrough (`/p/bailian/...`) ||
92+
93+
<Note>
94+
Embedding models (`text-embedding-v3`, `text-embedding-v4`) are served by
95+
the compatible-mode API but are **not** auto-discovered from the upstream
96+
`/v1/models` endpoint. Set `BAILIAN_MODELS=text-embedding-v3,text-embedding-v4`
97+
or use `CONFIGURED_PROVIDER_MODELS_MODE=allowlist` to make them available.
98+
</Note>
99+
100+
## References
101+
102+
- [Bailian documentation](https://www.alibabacloud.com/help/zh/model-studio/)
103+
- [OpenAI-compatible API reference](https://www.alibabacloud.com/help/zh/model-studio/compatibility-with-openai-responses-api)
104+
- [Qwen model list](https://www.alibabacloud.com/help/zh/model-studio/model-list)

docs/providers/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ quirks.
2525
| Z.ai | `ZAI_API_KEY` (`ZAI_BASE_URL` optional) ||
2626
| xAI (Grok) | `XAI_API_KEY` ||
2727
| MiniMax | `MINIMAX_API_KEY` (`MINIMAX_BASE_URL` optional) ||
28+
| Alibaba Cloud Bailian | `BAILIAN_API_KEY` (`BAILIAN_BASE_URL` optional) | [Alibaba Cloud Bailian](/providers/bailian) |
2829
| Xiaomi MiMo | `XIAOMI_API_KEY` (`XIAOMI_BASE_URL` optional) | [Xiaomi MiMo](/providers/xiaomi) |
2930
| Azure OpenAI | `AZURE_API_KEY` + `AZURE_BASE_URL` (`AZURE_API_VERSION` optional) | [Azure OpenAI](/providers/azure) |
3031
| Amazon Bedrock | `BEDROCK_BASE_URL` (region or endpoint) + AWS credentials | [Amazon Bedrock](/providers/bedrock) |

0 commit comments

Comments
 (0)