Skip to content

Update api-config.ts for dynamic API version prefix support#76

Closed
scalaview wants to merge 14 commits intosaturndec:mainfrom
scalaview:fix/support-dynamic-api-version-prefix-for-openai-api
Closed

Update api-config.ts for dynamic API version prefix support#76
scalaview wants to merge 14 commits intosaturndec:mainfrom
scalaview:fix/support-dynamic-api-version-prefix-for-openai-api

Conversation

@scalaview
Copy link

@scalaview scalaview commented Mar 6, 2026

Summary

修复使用 OpenAI 兼容 API 接入智谱时,由于智谱 base_url 包含 /v4 前缀而导致 API 调用报错的问题。

错误现象:

LLM_EMPTY_RESPONSE: openai-compatible:mmdjm7ns-6pdj5gt7::glm-4.7 返回空内容 [finishReason: unknown] [httpStatus: unknown] [apiError: {"name":"AI_APICallError","url":"[https://open.bigmodel.cn/api/paas/v4/v1/chat/completions","requestBodyValues":{"model":"glm-4.7","messages":[](https://open.bigmodel.cn/api/paas/v4/v1/chat/completions%22,%22requestBodyValues%22:%7B%22model%22:%22glm-4.7%22,%22messages%22:%5B)...]

问题根因:
当用户配置智谱 API 的 baseUrl 为 https://open.bigmodel.cn/api/paas/v4 时,原代码仅检查路径中是否包含 v1,未包含则强制追加 /v1,导致最终 URL 变成错误的 .../v4/v1/chat/completions

  • What changed:
  • 修改 normalizeProviderBaseUrl 函数的版本检测逻辑
    • 从检查路径是否包含 v1 改为检查最后一个路径段是否为版本标识符(支持 v1, v2, v4, v1beta, v1alpha 等)
    • 使用正则表达式 /^v\d+/ 匹配版本前缀,而非简单的字符串包含判断
  • Why:
  • 智谱 AI 使用 /v4 作为 API 版本前缀,而非标准的 /v1
  • 原逻辑无法识别 v4 为有效版本,导致错误地追加 /v1
  • 新逻辑支持任意 v 开头的数字版本前缀,兼容不同 API 提供商的版本规范
  • 遵循"统一与简洁"原则,通过通用正则匹配避免为每个版本号编写特殊逻辑

Architecture Plan Sync (Required)

  • Master plan file: /Users/earth/Desktop/waoowaoo/docs/architecture-unification-master-plan.md
  • I updated the phase status board (✅/🔄/⏸/⚠️) in the same PR.
  • I recorded concrete file-level changes under the corresponding phase.
  • I kept the plan date/current-context consistent with the code changes in this PR.

Phase Status Delta (Required)

Phase Before After Evidence (file path)
e.g. Phase 1.2 🔄 src/lib/query/task-target-overlay.ts

Guardrails Checklist (Required)

  • No compatibility layer introduced.
  • No silent fallback introduced.
  • No hidden default or fake data introduced.
  • Errors remain explicit and traceable.

Validation

  • Commands run:

    • npm run lint - 通过 ESLint 检查
    • npm run typecheck - 通过 TypeScript 类型检查
    • npm test - 通过相关单元测试
  • Manual verification:

    • 配置智谱 API baseUrl 为 https://open.bigmodel.cn/api/paas/v4
    • 调用 glm-4.7 模型成功返回响应
    • 验证最终请求 URL 为 https://open.bigmodel.cn/api/paas/v4/chat/completions(正确)
    • 验证配置标准 OpenAI baseUrl(无版本前缀)时仍正确追加 /v1

Risks

  • Known impact/risk:
    • 此修改仅影响 openai-compatible 类型的 provider
    • 对于已配置且正常工作的 provider(如标准 OpenAI),行为保持不变
    • 对于自定义版本前缀(如 v1beta, v2alpha),新逻辑能正确识别并保留
  • Follow-up tasks:
    • 如有其他提供商使用非标准版本前缀,可考虑扩展正则表达式或配置化版本检测规则

saturndec and others added 14 commits February 27, 2026 19:25
### ✨ 新功能
- 增加 OpenAI 兼容图片、视频格式支持
### 🐛 修复
- 修复默认模型配置后项目模型需要二次选择的问题
- 修复部分情况 resolution 无法读取的问题
- 修复模型链路为 LangGraph
- 修复默认参数无选择问题
- 修复关闭计费依然触发计费问题
- 修复 openai-compatible 被误判为原生 OpenAI 推理问题
- 修复 JSON 解析失败问题
### ⚙️ 优化
- 修改为默认计费 off
- 增强提示词 JSON 格式限制
### ✨ 新功能
- 增加 OpenAI 兼容图片、视频格式支持
### 🐛 修复
- 修复默认模型配置后项目模型需要二次选择的问题
- 修复部分情况 resolution 无法读取的问题
- 修复模型链路为 LangGraph
- 修复默认参数无选择问题
- 修复关闭计费依然触发计费问题
- 修复 openai-compatible 被误判为原生 OpenAI 推理问题
- 修复 JSON 解析失败问题
### ⚙️ 优化
- 修改为默认计费 off
- 增强提示词 JSON 格式限制
Updated beta notice for clarity and emphasis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants