Repository navigation
TokenRouter 0.8.4 introduces v2 advanced scheduler pool isolation and scenario presets, standalone DeepSeek OCR, TTS, and ASR tool endpoints, dynamic request-header templates with Gemini API-key header overrides, and time-based pricing for provider stats rules.
Upgrade notes
- Database migrations
326and327run automatically on startup and add nullable columns for provider stats time pricing (pricing_config_provider_stats_model_pricing.time_pricing) and DeepSeek tool pricing (pricing_configs.deepseek_ocr_price_per_1k_pages,deepseek_tts_price_per_10k_chars, anddeepseek_asr_price_per_hour). Migration327also backfillsdeepseek_ocr,deepseek_tts, anddeepseek_asrintocredentials.upstream_protocolsfor active DeepSeek API-key providers that already enabledeepseek_searchordeepseek_fetch; chat-only DeepSeek relays remain unchanged. Existing groups keep their currentallowed_protocols, so administrators must allowPOST /v1/tools/{ocr,tts,asr}per group before clients can call them. Reverting schema changes or the provider protocol backfill requires restoring a pre-upgrade database backup. - Existing groups using the
advancedscheduler now defaultpriority_modetotiered_spillover, serving traffic from lower numeric priority tiers until they reach load or health thresholds before spilling over to standby tiers. Groups that prefer mixing all priority tiers by weight can setpriority_modetoweightedin the group's advanced scheduler overrides.
New features
- Added v2 advanced scheduler candidate pool isolation (
active,standby_deferred, anddegraded_probation), multiplicative health gating(1 - decayed_error_rate)^2, scale-invariant Top-K sampling, and configurablepriority_mode(tiered_spilloverorweighted) with immediate standby tier probing when active tiers reach concurrency or session limits. - Added scenario preset cards (
coding_agent_sticky,low_latency_lb,primary_standby, andcustom), priority-mode controls, and real-time traffic-split simulation for unsaved draft overrides (POST /api/v1/admin/providers/:id/advanced-scheduler-score/preview) to the admin group advanced scheduler modal. - Added standalone DeepSeek OCR, TTS, and ASR endpoints (
POST /v1/tools/{ocr,tts,asr}and/tools/{ocr,tts,asr}) under thedeepseek_ocr,deepseek_tts, anddeepseek_asrprotocols, with pre-body user concurrency and funding checks, 104 MiB multipart upload limits for OCR and ASR, HTTP 200 payload checks, TLS fingerprint and proxy routing, and configurable operation billing (defaults:$0.225per 1K pages for OCR,$0.45per 10K characters for TTS, and$0.116per hour for ASR). - Added
per_requestpricing display separated from 1K/2K/4K image cards and group-scopeddeepseek-{search,fetch,ocr,tts,asr}tool cards in Model Marketplace, along with standalone DeepSeek tool connection testing andSystemRecorderaccounting using built-in PNG and WAV samples, optional bounded file uploads, and audio playback results. - Added single-pass
{{...}}dynamic request-header templates for providerheader_overridessupporting 20 built-in request variables (user, payer, team, API key, group, request ID, client IP, requested and upstream models, and provider identity), including 32-character provider-scoped HMAC-SHA256 digests (user.hash,payer.hash,team.hash, andapi_key.hash) derived via HKDF-SHA256 fromauth.jwt.secret. Templates suppress synthetic OAuth placeholder emails, preserve JSON literal braces, skip the entire header row when any referenced variable is empty or unavailable, and include a variable picker, expandable variable reference, and pre-submit validation inHeaderOverrideEditor. - Enabled custom request-header overrides for Gemini API-key providers across generation, model sync, single-model reads, Creative Studio runs, and batch image jobs, and wired request-scoped header rendering across HTTP, passthrough, WebSocket, media, search, and token-counting gateway paths.
- Added daily time-based multiplier support (
time_pricing) for token-mode custom provider stats pricing rules in the backend and admin Pricing view. Rules configured with onlytime_pricingand no explicit unit prices inherit the catalog base cost forupstream_modelwith built-in catalog time pricing replaced, or fall back when catalog fallback is unavailable or disabled; system usage recording passesrow.CreatedAtas the pricing timestamp.
Improvements
- Upgraded advanced scheduler runtime feedback with lazy time decay for idle error rates, consecutive failures, and model-scoped TTFT EWMA (tracked across client, group-mapped, and provider-mapped model keys), persisted across restarts in Redis (
sched:v6:runtime_feedback). Feedback reporting now covers OpenAI, Anthropic Messages, Gemini, and standalone DeepSeek tool paths with group-scoped EWMA alphas, excludes client-side validation rejections, deduplicates same-provider pool retries per request, keeps basic-group DeepSeek tool traffic out of shared runtime stats, and passes grouppriority_modeinto admin list score projections. - Improved sticky session recovery and failover in the advanced scheduler: sessions escape after 2 consecutive failures when sticky escape is enabled with an error-rate threshold in
(0, 0.5], retain their original bindings across temporary capacity escapes and slot waits, rebind only after a healthy replacement succeeds, and skip same-provider pool retries on degraded nodes when healthy group peers are available. - Added exact numeric user ID matching to admin user search alongside case-insensitive email, username, notes, and API key lookups, while ignoring leading zeros, signs, and non-ASCII digits so numeric text such as phone numbers does not trigger accidental ID matches.
Bug fixes
- Fixed rolling 24-hour and sub-day date ranges across
DateRangePicker, usage views, dashboards, rankings, payment dashboard, affiliate records, and usage exports to emit exact localYYYY-MM-DDTHH:mm:sstimestamps instead of date-only strings, resample active rolling presets on manual refresh while keeping bounds fixed across paging and sorting, and correctedKeyUsageView7-day and 30-day presets to cover exact local calendar day counts across DST transitions. - Fixed
UsageHandler.ListErrorsand affiliate record filter parsing to accept unzoned local datetimes and RFC3339 timestamps alongside date-only bounds, keeping explicit datetime end bounds exact while preserving full-day expansion for date-only inputs. - Fixed unsupported-model rejection responses (
GroupModelUnsupportedError) across OpenAI, Anthropic, and native Gemini endpoints so suggestions evaluate against the request's reasoning effort and thinking state, exclude the rejected model, report canonical supported reasoning efforts wheneffort_model_mappingrules exist, and respect grouprouting_policyallowlists and custom display lists.
📥 Installation
Docker:
# GitHub Container Registry
docker pull ghcr.io/tokenflux/tokenrouter:0.8.4One-line install (Linux):
curl -sSL https://raw.githubusercontent.com/TokenFlux/TokenRouter/main/deploy/install.sh | sudo bashManual download:
Download the appropriate archive for your platform from the assets below.
📚 Documentation
中文翻译
TokenRouter 0.8.4 引入高级调度器 v2 候选池隔离与场景预设、DeepSeek 独立 OCR / TTS / ASR 工具端点、动态请求头模板与 Gemini API Key 请求头覆盖,以及提供商统计价卡的分时计费支持。
升级说明
- 启动时会自动执行数据库迁移
326与327,分别新增提供商统计分时计费的可空列(pricing_config_provider_stats_model_pricing.time_pricing)与 DeepSeek 工具单价的可空列(pricing_configs.deepseek_ocr_price_per_1k_pages、deepseek_tts_price_per_10k_chars、deepseek_asr_price_per_hour)。迁移327还会为存量活跃且已开启deepseek_search或deepseek_fetch的 DeepSeek API Key 提供商在credentials.upstream_protocols中回填deepseek_ocr、deepseek_tts与deepseek_asr;仅开启文本协议的 DeepSeek 中转保持不变。已有分组维持当前allowed_protocols,管理员需按分组放行POST /v1/tools/{ocr,tts,asr}后客户端才可调用。如需撤销表结构变更或提供商协议回填,需恢复升级前的数据库备份。 - 使用
advanced调度器的存量分组现默认采用priority_mode = tiered_spillover,优先由较小数值优先级梯队承接流量,达到负载或健康阈值后再溢出至备用梯队。如需按权重混合所有优先级梯队,可在分组的高级调度覆盖中将priority_mode设为weighted。
新增功能
- 新增高级调度器 v2 候选池隔离(
active、standby_deferred、degraded_probation)、健康乘子评分(1 - decayed_error_rate)^2、尺度无关的 Top-K 抽样,以及可配置的priority_mode(tiered_spillover或weighted),当主力梯队触及并发或会话上限时立即探测备用梯队。 - 管理端分组高级调度弹窗新增场景预设卡片(
coding_agent_sticky、low_latency_lb、primary_standby、custom)、优先级模式配置,以及针对未保存草稿覆盖参数的实时分流模拟(POST /api/v1/admin/providers/:id/advanced-scheduler-score/preview)。 - 新增 DeepSeek 独立 OCR、TTS、ASR 端点(
POST /v1/tools/{ocr,tts,asr}与/tools/{ocr,tts,asr}),注册deepseek_ocr、deepseek_tts、deepseek_asr协议,支持读体前用户并发与余额校验、OCR/ASR 104 MiB multipart 上传上限、HTTP 200 载荷校验、TLS 指纹与代理路由,以及可配置操作单价(默认 OCR$0.225/千页、TTS$0.45/万字符、ASR$0.116/小时)。 - 模型广场新增独立于 1K/2K/4K 图片价卡的
per_request价格展示,并生成按分组生效的deepseek-{search,fetch,ocr,tts,asr}工具卡片;同步支持 DeepSeek 独立工具提供商连接测试与SystemRecorder记账,提供内置 PNG 与 WAV 样本、可选有界文件上传以及音频播放结果。 - 提供商
header_overrides新增单遍解析的{{...}}动态请求头模板,支持 20 个内置请求变量(用户、付款方、团队、API Key、分组、请求 ID、客户端 IP、请求模型与上游模型、提供商标识),包含基于auth.jwt.secret经 HKDF-SHA256 派生的 32 位提供商隔离 HMAC-SHA256 摘要(user.hash、payer.hash、team.hash、api_key.hash)。模板会抑制合成 OAuth 占位邮箱、保留 JSON 字面量花括号、在任意引用变量为空或不可用时跳过整行请求头,并在HeaderOverrideEditor中提供变量插入菜单、可展开变量说明和提交前模板校验。 - 为 Gemini API Key 提供商开启自定义请求头覆盖,覆盖生成请求、模型同步、单模型读取、创作台运行与批量图片任务,并在 HTTP、透传、WebSocket、媒体、搜索和 Token 计数网关路径接入请求级请求头渲染。
- 后端与管理端价格配置页的 token 模式自定义提供商统计价卡新增每日分时倍率(
time_pricing)支持。仅配置time_pricing而未填显式单价的规则,会按upstream_model继承目录基础成本并替换目录内置分时,在目录回退禁用或缺失时继续回退;系统用量记录写入row.CreatedAt作为计费时间戳。
功能改进
- 升级高级调度器运行时反馈,为空闲错误率、连续失败次数和按模型维度的 TTFT EWMA(按客户端模型、分组映射模型和提供商映射模型记录)引入惰性时间衰减,并通过 Redis(
sched:v6:runtime_feedback)持久化跨重启恢复。反馈上报现覆盖 OpenAI、Anthropic Messages、Gemini 与 DeepSeek 独立工具路径并采用分组级 EWMA alpha,排除客户端校验拒绝,对同请求内同提供商池重试去重,使基础分组的 DeepSeek 工具流量不写入共享运行时统计,并将分组priority_mode传入管理端列表评分预览。 - 改进高级调度器的粘性会话恢复与故障转移:启用粘性逃逸且错误率阈值在
(0, 0.5]时连续失败 2 次即可触发逃逸;临时容量逃逸与等待槽位期间保留原绑定,仅在健康替代节点成功服务后重绑;当同组存在健康节点时,跳过已降级节点的同提供商池重试。 - 管理端用户搜索在保留不区分大小写的邮箱、用户名、备注与 API Key 匹配外,新增精确正整数用户 ID 匹配,同时忽略前导零、正负号与非 ASCII 数字,避免手机号等数字文本误触发 ID 查找。
问题修复
- 修复
DateRangePicker、用量页、仪表盘、排行榜、支付仪表盘、推广记录与用量导出中近 24 小时及跨小时滚动时间范围仅发送日期字符串的问题,统一输出精确本地YYYY-MM-DDTHH:mm:ss时间戳;手动刷新时重新采样当前滚动预设,分页和排序期间保持区间固定;同时修复KeyUsageView的 7 天与 30 天预设,在夏令时切换下仍覆盖准确的本地自然日天数。 - 修复
UsageHandler.ListErrors与推广记录筛选的时间解析,在兼容纯日期边界的同时支持无时区本地日期时间和 RFC3339 时间戳,对显式日期时间结束边界保持精确值,对纯日期输入保留整天扩展。 - 修复 OpenAI、Anthropic 与原生 Gemini 端点中模型不支持拒绝响应(
GroupModelUnsupportedError)的候选项生成逻辑,改为按当前请求的推理档位与 thinking 状态评估候选模型、排除被拒模型本身、在存在effort_model_mapping规则时返回规范支持的推理档位,并应用分组routing_policy白名单和自定义展示列表过滤。
📥 安装
Docker:
# GitHub Container Registry
docker pull ghcr.io/tokenflux/tokenrouter:0.8.4一键安装(Linux):
curl -sSL https://raw.githubusercontent.com/TokenFlux/TokenRouter/main/deploy/install.sh | sudo bash手动下载:
请从下方附件中下载适用于您平台的压缩包。