Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ API Key: <刚才创建的客户端密钥>
Go 网关统一鉴权、调度和记录请求。已存 PAT 的 Qoder 账号在进程内直连;仍使用旧 CLI 凭证的 Qoder 账号保留每账号一个 Node 进程和 HOME。其余供应商走进程内适配器,不为每次请求启动完整 CLI。

- **三种接口**:Chat Completions、Responses、Anthropic Messages,加上模型列表。支持流式和函数工具调用。
- **多账号**:轮询、加权轮询、顺序填满,以及可选的同供应商最早到期优先(FEFO)。自动选号、会话粘性、并发限制、冷却和故障切换都在。
- **多账号**:轮询、加权轮询、顺序填满、剩余额度最少/最多优先,以及可选的同供应商最早到期优先(FEFO)。自动选号、会话粘性、并发限制、冷却和故障切换都在。
- **一个控制台**:账号、模型、客户端密钥、代理、额度和请求日志。
- **Docker**:账号数据持久化。可选的宿主机更新器可以在控制台里下载、确认和回滚。

Expand All @@ -85,6 +85,12 @@ Qoder 国内版、WorkBuddy、Trae 已实现,真账号验收未完成。Kimi C

只在同一供应商内,按最近一笔还能用的积分包到期日排序。没有到期日的账号不猜测,只在有日期的账号都不可用时才上场。额度耗尽、冷却、并发占满的账号照旧先退出。目前只有 WorkBuddy 个人账号有逐包到期日。

## 剩余额度优先

在「系统 → 账号调度策略」里选「剩余额度最少优先」或「剩余额度最多优先」,也可以提交 `{"routing_strategy":"least-quota-first"}` / `{"routing_strategy":"most-quota-first"}` 到 `PATCH /api/system/settings`。模型池也支持同名策略。

按剩余额度百分比排序:优先使用 `remaining / total`;没有 `total` 时用 `100 - percentage`。不同供应商的额度单位不能直接比较,所以这里只用比例;额度未知的账号排在最后。

<p>
<img src="./docs/assets/readme/section-limits-zh.svg" width="100%" alt="03 它不做什么">
</p>
Expand Down
8 changes: 7 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Connect **Qoder (Global / CN)**, **WorkBuddy (Global / CN)**, and **Trae CN Work
The Go gateway handles authentication, routing, and request logging. PAT-backed Qoder accounts talk to the upstream in-process. Qoder accounts that still use the legacy CLI credential keep one Node process and HOME each. Other providers use in-process adapters, so no full CLI starts per request.

- **Three APIs**: Chat Completions, Responses, and Anthropic Messages, plus model listing. Streaming and function tools included.
- **Many accounts**: round-robin, weighted round-robin, fill-first, and opt-in same-provider earliest-expiry-first (FEFO). Automatic selection, session affinity, concurrency limits, cooldowns, and failover stay on.
- **Many accounts**: round-robin, weighted round-robin, fill-first, least/most remaining quota first, and opt-in same-provider earliest-expiry-first (FEFO). Automatic selection, session affinity, concurrency limits, cooldowns, and failover stay on.
- **One console**: accounts, models, client keys, proxies, quotas, and request logs.
- **Docker**: account data persists. An optional host updater downloads, confirms, and rolls back from the console.

Expand All @@ -85,6 +85,12 @@ Choose **Earliest expiry first (FEFO)** under **System → Account routing strat

Accounts are ranked only inside one provider, by the nearest credit package that can still be spent. Missing dates are never guessed, and those accounts join only after every dated account is unavailable. Exhausted, cooling, and concurrency-saturated accounts still drop out first. Only WorkBuddy personal accounts currently expose a per-package expiry.

## Remaining quota first

Choose **Least remaining quota first** or **Most remaining quota first** under **System → Account routing strategy**, or send `{"routing_strategy":"least-quota-first"}` / `{"routing_strategy":"most-quota-first"}` to `PATCH /api/system/settings`. Aggregation model pools support the same strategy names.

Accounts are ranked by remaining quota ratio: `remaining / total` is preferred, and `100 - percentage` is used when no total exists. Raw remaining values are not comparable across providers with different units, so only ratios are used; accounts with unknown quota sort last.

<p>
<img src="./docs/assets/readme/section-limits-en.svg" width="100%" alt="03 What it will not do">
</p>
Expand Down
13 changes: 13 additions & 0 deletions changelog/unreleased/ccswitch-alignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### English

- Align reasoning conversion with CC Switch: accept `ultra` as the deepest tier and normalize Anthropic `thinking.budget_tokens` (2048 / 8192 / 16384 / 24576) onto the catalog-driven reasoning ladder.
- Unify provider reasoning intent parsing behind one shared parser while keeping each provider's legacy wire behavior: explicit `thinking:{"type":"disabled"}` stays a separate off switch, and effort strings, effort objects, and enable-thinking flags resolve as before.
- Canonicalize protocol usage across Anthropic, OpenAI chat, and Responses streams: `input_tokens` now excludes cache read/write, cache buckets are always reported, and usage fields from provider aliases (`cache_read_input_tokens`, `cached_tokens`, `cache_creation_input_tokens`) are folded into one shape.
- Keep Trae max mode client-owned: only an explicit `is_max_mode` request is forwarded, never inferred from the catalog or a stored console setting.

### 中文

- 推理转换对齐 CC Switch 约定:接受 `ultra` 作为最深档,并把 Anthropic `thinking.budget_tokens`(2048 / 8192 / 16384 / 24576)归一化到由 catalog 驱动的推理档位。
- 用统一的解析器处理各供应商的推理意图,同时保持各自的旧有请求行为:`thinking:{"type":"disabled"}` 仍是独立的关闭开关,effort 字符串、effort 对象和 enable-thinking 开关的解析结果不变。
- 统一 Anthropic、OpenAI chat 和 Responses 流的 usage 口径:`input_tokens` 不再包含缓存读写,缓存字段始终上报,并把供应商别名(`cache_read_input_tokens`、`cached_tokens`、`cache_creation_input_tokens`)折算为同一形状。
- Trae 的 Max 模式保持由客户端决定:只有请求显式带上 `is_max_mode` 才透传,不再从 catalog 或控制台保存的设置推断。
11 changes: 11 additions & 0 deletions changelog/unreleased/context-window-passthrough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### English

- Chat requests no longer receive a cli2api-chosen context window. Only a context window supplied by the client is forwarded; catalog context limits, including each model's maximum context, are display-only. Trae max mode is likewise forwarded only when the client asks for it.
- The console no longer stores a per-model context window and no longer exposes the Trae/Qoder max-mode switches. Installations that had set them stop applying those values after upgrade; no stored setting is migrated.
- Align reasoning conversion with CC Switch conventions: accept `ultra` as the deepest tier and normalize Anthropic thinking budgets into the catalog-driven reasoning ladder.

### 中文

- 聊天请求不再由 cli2api 约定上下文窗口;只透传客户端传入的上下文窗口。目录中的上下文上限(包括每个模型的最大上下文窗口)仅作展示。Trae 的最大档位同样只按客户端请求透传。
- 控制台不再保存“每个模型的上下文窗口”,也不再提供 Trae/Qoder 最大档开关。已经设置过这些值的实例升级后不再生效,且不会迁移已存配置。
- 推理转换对齐 CC Switch 约定:接受 `ultra` 作为最深档,并把 Anthropic thinking budget 归一化到由 catalog 驱动的推理档位。
13 changes: 13 additions & 0 deletions changelog/unreleased/cross-provider-model-pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### English

- Added a "Cross-provider model pool" page between Models and Access. It appears only while the existing cross-provider model pool setting is enabled, and toggling that setting updates the navigation immediately.
- You can now define logical models that aggregate multiple real provider models behind one client-facing ID, for both same-named models across providers and differently named models. Each logical model has its own routing strategy (priority order, round robin, fill first, or FEFO), failover settings, and an ordered, weighted member list.
- `/v1/models` now exposes the logical IDs instead of the aggregated per-provider entries; member capabilities are merged conservatively. Logical models are served through the existing route loop and failover/cooldown system, with cooldowns recorded against the real member model. The per-model strategy (priority order by default, round robin, fill first, FEFO) and member weights are honored during routing; priority order keeps using the first healthy member and falls through on failure.
- Each API key now has its own "Model aggregation mode" switch in the create/edit dialog. When on, the provider cards are greyed out and the key stores only the aggregation grant, so it can call logical models but cannot pin or directly use real provider models; when off, the key keeps its normal provider selection. Key cards show "Model aggregation mode" instead of a provider list for such keys.

### 中文

- 在“模型”和“接入与调试”之间新增“跨 Provider 模型池”页面;仅当现有的跨 Provider 模型池开关开启时出现,切换开关后导航会立即更新。
- 现在可以定义逻辑模型,把多个真实供应商模型聚合到同一个客户端 ID 下,既支持跨供应商的同名模型,也支持不同名称的模型。每个逻辑模型都可以单独配置路由策略(优先级顺序、轮询、优先填满或 FEFO)、故障转移规则,以及有序带权重的成员列表。
- `/v1/models` 现在返回聚合后的逻辑 ID,而不再展示被聚合的逐供应商条目;成员能力按保守方式合并。逻辑模型复用现有选路与故障转移/冷却体系,冷却记录在真实成员模型上。每个逻辑模型的策略和成员权重现在真正参与选路;优先级顺序会持续使用第一个健康成员并在失败时顺延,未配置时默认按优先级顺序。
- 每个 API 密钥在创建/编辑弹窗中新增“模型聚合模式”开关:开启后供应商卡片变灰不可选,密钥仅保存聚合授权,可调用逻辑模型但不能固定或直接使用真实供应商模型;关闭时维持原有供应商选择。此类密钥在卡片上显示“模型聚合模式”而非供应商列表。
11 changes: 11 additions & 0 deletions changelog/unreleased/model-availability-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### English

- Added a one-click model availability check on the Models page. It sends one minimal 1-token, thinking-disabled live request per model per available account, then reports per-account reachability and latency without changing routing cooldowns or the Usage page totals; each probe still consumes one real 1-token upstream request from that account's quota.
- The Models page status column now shows the latest availability result instead of custom/default settings, and the action column is labeled Model details.
- Removed the console reasoning-strength default selector. The Models page now shows the maximum context, the reasoning levels each model actually declares, and image input capability.

### 中文

- 模型页新增一键可通性检查:对“每个模型 × 每个可用账号”发送一次仅 1 token、关闭思考的真实请求,返回逐账号可通状态与延迟,且不会改变路由冷却状态或用量页统计;每次探测会真实消耗该账号的一次 1 token 上游额度。
- 模型页状态列改为显示最近一次可通性检查结果,不再显示默认/自定义;操作表头改为“模型详情”。
- 移除控制台推理强度默认选择器;模型页改为展示最大上下文、每个模型实际声明的思考档位和图片输入能力。
11 changes: 11 additions & 0 deletions changelog/unreleased/quota-aware-routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### English

- Added `least-quota-first` and `most-quota-first` routing strategies for both global account scheduling and aggregation model pools. They rank accounts by remaining quota ratio and place accounts with unknown quota last.
- Fixed model-pool strategy overrides so FEFO candidate counting matches account selection, and normalized stored aggregation strategies so legacy/case-variant values do not silently fall back to round robin.
- Aggregated model-pool failover no longer pins the first member's region or recomputes the plan's attempt budget, so cross-provider members stay reachable and MaxAttempts is honored.

### 中文

- 新增 `least-quota-first`(剩余额度最少优先)和 `most-quota-first`(剩余额度最多优先)路由策略,全局账号调度和模型池都可使用;按剩余额度百分比排序,额度未知的账号排在最后。
- 修复模型池策略覆盖时 FEFO 候选计数与实际选号不一致的问题,并在读取存储的模型池策略时做归一化,避免历史大小写或旧值静默退回轮询。
- 聚合模型池的故障转移不再锁定首个成员的 region,也不再重算尝试预算,跨供应商成员仍可被尝试,配置的 MaxAttempts 会被遵守。
2 changes: 2 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SystemPage } from '@/pages/SystemPage'
import { LogsPage } from '@/pages/LogsPage'
import { UsagePage } from '@/pages/UsagePage'
import { KeysPage } from '@/pages/KeysPage'
import { ModelPoolPage } from '@/pages/ModelPoolPage'

export default function App() {
return (
Expand All @@ -29,6 +30,7 @@ export default function App() {
<Route path="/" element={<OverviewPage />} />
<Route path="/auth" element={<Navigate to="/accounts" replace />} />
<Route path="/providers" element={<ProvidersPage />} />
<Route path="/model-pool" element={<ModelPoolPage />} />
<Route path="/access" element={<AccessPage />} />
<Route path="/accounts" element={<AccountsPage />} />
<Route path="/checkins" element={<Navigate to="/accounts" replace />} />
Expand Down
56 changes: 56 additions & 0 deletions frontend/src/api/modelPools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { api } from './client'

export type AggregationMember = {
id?: number
provider: string
region?: string
model: string
priority: number
weight: number
}

export type AggregationRecord = {
id: string
name: string
enabled: boolean
strategy: string
allow_fallbacks: boolean
max_attempts: number
members: AggregationMember[]
created_at: string
updated_at: string
}

export type AggregationInput = {
id?: string
name: string
enabled?: boolean
strategy: string
allow_fallbacks?: boolean
max_attempts: number
members: AggregationMember[]
}

export function fetchAggregations() {
return api<{ object: string; data: AggregationRecord[] }>('/api/aggregations')
}

export function createAggregation(input: AggregationInput) {
return api<AggregationRecord>('/api/aggregations', {
method: 'POST',
body: JSON.stringify(input),
})
}

export function updateAggregation(id: string, input: Partial<AggregationInput>) {
return api<AggregationRecord>(`/api/aggregations/${encodeURIComponent(id)}`, {
method: 'PATCH',
body: JSON.stringify(input),
})
}

export function deleteAggregation(id: string) {
return api(`/api/aggregations/${encodeURIComponent(id)}`, { method: 'DELETE' })
}

export const AGGREGATION_STRATEGIES = ['priority', 'round-robin', 'fill-first', 'fefo', 'least-quota-first', 'most-quota-first'] as const
40 changes: 40 additions & 0 deletions frontend/src/api/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,46 @@ export function refreshAccount(accountId: string, options?: { quota?: boolean })
})
}

export type ModelProbeAccountResult = {
account_id: string
provider?: string
region?: string
ok: boolean
status?: number
code?: string
kind?: string
message?: string
latency_ms: number
}

export type ModelProbeResult = {
model: string
ok: boolean
account_id?: string
provider?: string
status?: number
code?: string
kind?: string
message?: string
latency_ms: number
attempt_count?: number
accounts?: ModelProbeAccountResult[]
}

export type ModelProbeResponse = {
results: ModelProbeResult[]
summary: { total: number; passed: number; failed: number; skipped: number }
elapsed_ms: number
}

/** Send one minimal token request per model to verify real availability. */
export function checkModels(models?: string[]) {
return api<ModelProbeResponse>('/api/models/check', {
method: 'POST',
body: JSON.stringify(models?.length ? { models } : {}),
})
}

export function testChat(model: string, content: string, accountId?: string) {
const headers: Record<string, string> = {}
if (accountId) headers['X-Qoder-Account'] = accountId
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type SystemSettings = {
cross_provider_model_pool: boolean
checkin_disabled_accounts: boolean
proxy_url: string
routing_strategy: 'round-robin' | 'weighted-round-robin' | 'fill-first' | 'fefo'
routing_strategy: 'round-robin' | 'weighted-round-robin' | 'fill-first' | 'fefo' | 'least-quota-first' | 'most-quota-first'
workbuddy_checkin_time: string
checkin_times: Record<string, string>
timezone: string
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ export type ModelInfo = {
max_output_tokens_max?: number
prompt_max_tokens_max?: number
reasoning_options?: string[]
reasoning_option_values?: string[]
reasoning_default?: string
reasoning_effort?: string
reasoning_type?: string
can_disable_thinking?: boolean
supports_images?: boolean
}

export type CheckinRecord = {
Expand Down
Loading
Loading