sub2api
sub2api copied to clipboard
feat: Responses API thinking/reasoning 字段撞针回退策略
背景
当 sub2api 转发 Responses API 请求到不同上游提供商时,各供应商对思考能力参数的格式要求不同:
- OpenAI 标准:
reasoning: {effort: "high"} - Anthropic 标准:
thinking: {type: "enabled", budget_tokens: 64000} - 火山引擎/Doubao: 同时需要
thinking和reasoning两个字段
当前 sub2api 仅发送 reasoning 字段(OpenAI 格式),当上游不支持该格式时请求会失败。
需求
实现撞针降级重试策略:
- Stage 1(当前行为):仅发送
reasoning - Stage 2:收到 thinking/reasoning 相关 400 错误 → 添加
thinking字段(双字段并存) - Stage 3:仍然失败 → 移除
reasoning,仅保留thinking
技术要点
- 仅在 400 错误消息匹配 thinking/reasoning 关键词时激活
- 硬上限 2 次额外重试,不会无限循环
- 管理后台可控(请求整流器设置,默认开启)
- 涉及两条转发路径:passthrough 和 native HTTP
- 使用 gjson/sjson 操作原始 JSON,与现有 FilterThinkingBlocksForRetry 模式一致
影响范围
- 12 个文件修改
- 新增 26 个单元测试用例