Skip to content
Merged
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 @@ Stable support covers **Qoder (Global / CN)**, **WorkBuddy (Global / CN)**, and
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
15 changes: 15 additions & 0 deletions changelog/unreleased/account-routing-failover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### English

- Release the implicit region latch on cross-provider routes so a bare model shared by multiple providers can fail over to another supplier.
- Keep the Qoder global/CN region isolation for provider-scoped routes.
- Preserve the retry budget after the first pick instead of shrinking it to the pinned region's account count.
- Give each priority tier its own retry budget so sibling accounts cannot consume the whole budget before a lower-priority provider is reached.
- Apply account model aliases in the legacy worker request path.

### 中文

- 跨供应商裸模型路由不再被第一次选中的 region 隐式锁住,失败后可以切换到其他供应商。
- Qoder 等 provider-scoped 路由继续保持 global/CN 区域隔离。
- 首次选号后保留原重试预算,不再按 pinned region 的账号数量缩小 attempts。
- 每个 priority tier 使用独立重试预算,避免第一供应商的 sibling accounts 耗尽全局预算,导致低优先级供应商完全无法被尝试。
- legacy worker 请求路径也应用账号模型别名。
11 changes: 11 additions & 0 deletions changelog/unreleased/aggregation-account-deployments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### English

- Add `account_id` to aggregation members so one logical model can target a specific account/deployment instead of fanning out over every account of a provider.
- Persist the field in SQLite and expose it through the console API and model pool editor.
- Keep legacy members without `account_id` on the existing provider/region pool behavior.

### 中文

- 聚合成员新增 `account_id`,让一个逻辑模型可以固定到一个具体账号/deployment,而不是默认在该供应商下扇出到所有账号。
- 该字段持久化到 SQLite,并通过控制台 API 和模型池编辑器暴露。
- 未填写 `account_id` 的旧成员保持原有 provider/region 池行为。
11 changes: 11 additions & 0 deletions changelog/unreleased/cross-provider-model-pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### 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.

### 中文

- 在“模型”和“接入与调试”之间新增“跨 Provider 模型池”页面;仅当现有的跨 Provider 模型池开关开启时出现,切换开关后导航会立即更新。
- 现在可以定义逻辑模型,把多个真实供应商模型聚合到同一个客户端 ID 下,既支持跨供应商的同名模型,也支持不同名称的模型。每个逻辑模型都可以单独配置路由策略(优先级顺序、轮询、优先填满或 FEFO)、故障转移规则,以及有序带权重的成员列表。
- `/v1/models` 现在返回聚合后的逻辑 ID,而不再展示被聚合的逐供应商条目;成员能力按保守方式合并。逻辑模型复用现有选路与故障转移/冷却体系,冷却记录在真实成员模型上。每个逻辑模型的策略和成员权重现在真正参与选路;优先级顺序会持续使用第一个健康成员并在失败时顺延,未配置时默认按优先级顺序。
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 上游额度。
- 模型页状态列改为显示最近一次可通性检查结果,不再显示默认/自定义;操作表头改为“模型详情”。
- 移除控制台推理强度默认选择器;模型页改为展示最大上下文、每个模型实际声明的思考档位和图片输入能力。
15 changes: 15 additions & 0 deletions changelog/unreleased/prompt-cache-affinity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### English

- Keep aggregate logical-model sessions bound to a member account instead of resetting to the general pool on every turn.
- Bind a streaming request as soon as the upstream accepts the response headers/first event, not after the body ends; a follow-up turn can then reuse the same account while the first stream is still running.
- Always bind, cool down, and fail over by pool account ID. Worker response labels are never used as routing keys.
- Invalidate a session binding on failover, including sticky escapes.
- Canonicalize provider cache token fields so reported cache usage is stable across provider protocols.

### 中文

- 聚合逻辑模型的会话持续绑定到成员账号,不再每轮重置为通用路由池。
- 流式请求在上游接受响应头/首个成功事件时就完成绑定,而不是等整个响应体结束;第一轮流式请求尚未结束时,下一轮也能复用同一账号。
- 绑定、冷却和故障转移全部使用 pool account ID;worker 回写的响应标签不会作为路由键。
- 发生 failover 时失效会话绑定,包括 sticky-escape 场景。
- 统一各 provider 的缓存 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 会被遵守。
3 changes: 3 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { I18nProvider } from '@/hooks/useI18n'
import { OverviewProvider } from '@/hooks/useOverview'
import { ThemeProvider } from '@/hooks/useTheme'


const LoginPage = lazy(() => import('@/pages/LoginPage').then((module) => ({ default: module.LoginPage })))

const OverviewPage = lazy(() => import('@/pages/OverviewPage').then((module) => ({ default: module.OverviewPage })))
const ProvidersPage = lazy(() => import('@/pages/ProvidersPage').then((module) => ({ default: module.ProvidersPage })))
const ModelPoolPage = lazy(() => import('@/pages/ModelPoolPage').then((module) => ({ default: module.ModelPoolPage })))
const AccessPage = lazy(() => import('@/pages/AccessPage').then((module) => ({ default: module.AccessPage })))
const AccountsPage = lazy(() => import('@/pages/AccountsPage').then((module) => ({ default: module.AccountsPage })))
const SystemPage = lazy(() => import('@/pages/SystemPage').then((module) => ({ default: module.SystemPage })))
Expand All @@ -34,6 +36,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
57 changes: 57 additions & 0 deletions frontend/src/api/modelPools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { api } from './client'

export type AggregationMember = {
id?: number
provider: string
region?: string
model: string
account_id?: 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