Skip to content

TokenRouter 0.8.4

Latest

Choose a tag to compare

@github-actions github-actions released this 03 Dec 21:19
· 4 commits to main since this release

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 326 and 327 run 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, and deepseek_asr_price_per_hour). Migration 327 also backfills deepseek_ocr, deepseek_tts, and deepseek_asr into credentials.upstream_protocols for active DeepSeek API-key providers that already enable deepseek_search or deepseek_fetch; chat-only DeepSeek relays remain unchanged. Existing groups keep their current allowed_protocols, so administrators must allow POST /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 advanced scheduler now default priority_mode to tiered_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 set priority_mode to weighted in the group's advanced scheduler overrides.

New features

  • Added v2 advanced scheduler candidate pool isolation (active, standby_deferred, and degraded_probation), multiplicative health gating (1 - decayed_error_rate)^2, scale-invariant Top-K sampling, and configurable priority_mode (tiered_spillover or weighted) 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, and custom), 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 the deepseek_ocr, deepseek_tts, and deepseek_asr protocols, 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.225 per 1K pages for OCR, $0.45 per 10K characters for TTS, and $0.116 per hour for ASR).
  • Added per_request pricing display separated from 1K/2K/4K image cards and group-scoped deepseek-{search,fetch,ocr,tts,asr} tool cards in Model Marketplace, along with standalone DeepSeek tool connection testing and SystemRecorder accounting using built-in PNG and WAV samples, optional bounded file uploads, and audio playback results.
  • Added single-pass {{...}} dynamic request-header templates for provider header_overrides supporting 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, and api_key.hash) derived via HKDF-SHA256 from auth.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 in HeaderOverrideEditor.
  • 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 only time_pricing and no explicit unit prices inherit the catalog base cost for upstream_model with built-in catalog time pricing replaced, or fall back when catalog fallback is unavailable or disabled; system usage recording passes row.CreatedAt as 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 group priority_mode into 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 local YYYY-MM-DDTHH:mm:ss timestamps instead of date-only strings, resample active rolling presets on manual refresh while keeping bounds fixed across paging and sorting, and corrected KeyUsageView 7-day and 30-day presets to cover exact local calendar day counts across DST transitions.
  • Fixed UsageHandler.ListErrors and 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 when effort_model_mapping rules exist, and respect group routing_policy allowlists and custom display lists.

📥 Installation

Docker:

# GitHub Container Registry
docker pull ghcr.io/tokenflux/tokenrouter:0.8.4

One-line install (Linux):

curl -sSL https://raw.githubusercontent.com/TokenFlux/TokenRouter/main/deploy/install.sh | sudo bash

Manual 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

手动下载:
请从下方附件中下载适用于您平台的压缩包。

📚 文档