Makememo / Makememo/MemoAI

[Bug] 智谱AI 使用默认 Base URL 时连接测试错误回退到 OpenAI,返回 401

Open
#426 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
No language data
Stars
1.1k
Forks
108
PR merge metrics
No merged PRs in 30d

Description

问题描述

在 Memo 1.8.3 中配置智谱AI时,即使填写了正确的智谱 Base URL,连接测试仍可能把请求发送到 OpenAI,最终返回 OpenAI 的 401 API Key 错误。

该问题可以使用内置的 glm-5.2 稳定复现,因此与新增加的 glm-5.3-flash 模型本身无关。

环境

  • Memo:1.8.3
  • 系统:macOS
  • 服务商:智谱AI
  • 测试模型:glm-5.2
  • Base URL:https://open.bigmodel.cn/api/paas/v4

复现步骤

  1. 打开 Memo 设置中的大模型服务。
  2. 选择“智谱AI”。
  3. 输入有效的智谱 API Key。
  4. 将 Base URL 设置为:

错误信息中的 platform.openai.com 表明请求实际上被发送到了 OpenAI,而不是智谱。
预期结果
Memo 应向以下智谱接口发送请求:
https://open.bigmodel.cn/api/paas/v4/chat/completions
不应在智谱 Base URL 已配置的情况下回退到 https://api.openai.com/v1。
初步定位
从 Memo 1.8.3 打包代码观察到,可能存在以下调用链:

  1. 当用户配置的 baseURL 与服务商的 defaultBaseURL 完全相同时,前端表单会将该字段转换为空值。

  2. 连接测试仍会传递 baseURL: ""。

  3. 后端配置合并顺序类似:

    https://open.bigmodel.cn/api/paas/v4

  4. 选择 glm-5.2

  5. 保存配置并点击“连接测试”。

实际结果

连接测试失败,并返回来自 OpenAI 的错误:

401 Incorrect API key provided: [REDACTED]
You can find your API key at https://platform.openai.com/account/api-keys.
Troubleshooting URL:
https://js.langchain.com/docs/troubleshooting/errors/MODEL_AUTHENTICATION/


{
  ...providerDefaults,
  ...userConfig
}
  1. 空字符串覆盖了正确的默认 Base URL。
  2. getOpenAIClientConfiguration("") 没有返回自定义地址。
  3. OpenAI SDK 因此使用默认的 https://api.openai.com/v1。
    建议检查:
  • 默认 Base URL 是否不应从测试参数中移除;
  • 空字符串是否不应覆盖服务商默认配置;
  • 合并前是否应把空白 Base URL 归一化为 undefined;
  • 连接错误中能否显示实际请求主机,便于诊断。
    临时解决办法
    在 Base URL 末尾增加 /:
    https://open.bigmodel.cn/api/paas/v4/
    由于该字符串不再与内置默认值完全相同,连接测试可能正确使用智谱地址。
    这只是临时规避方式,正式修复仍应保证默认 Base URL 不会被空字符串覆盖。
    补充影响
    该逻辑可能不只影响智谱AI,也可能影响其他采用 OpenAI-compatible 协议、并使用内置默认 Base URL 的服务商。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the connection-test path and inspect getOpenAIClientConfiguration, especially how an empty baseURL is merged with providerDefaults. Reproduce the glm-5.2 test with the default 智谱 URL, then verify that the request uses https://open.bigmodel.cn/api/paas/v4/chat/completions rather than the OpenAI fallback.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
57/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.