Skip to content

fix(ai): ensure Anthropic provider baseURL includes /v1 (#1248) - #1291

Open
Aniketchavan7 wants to merge 1 commit into
blinkospace:mainfrom
Aniketchavan7:fix/anthropic-provider-baseurl
Open

Aniketchavan7 wants to merge 1 commit into
blinkospace:mainfrom
Aniketchavan7:fix/anthropic-provider-baseurl

Conversation

@Aniketchavan7

Copy link
Copy Markdown

Fixes #1248

Problem

When setting up Anthropic using the default provider template under Settings -> AI, the template defaulted defaultBaseURL to https://api.anthropic.com.
@ai-sdk/anthropic expects baseURL to include the API version prefix (its internal default is https://api.anthropic.com/v1). Because passing the bare domain overrides that default without /v1, requests were dispatched to https://api.anthropic.com/messages, which returns HTTP 404 Not Found.

Solution

  1. Updated PROVIDER_TEMPLATES in app/src/components/BlinkoSettings/AiSetting/constants.tsx to set defaultBaseURL: 'https://api.anthropic.com/v1' (matching OpenAI and Voyage templates).
  2. Added defensive normalization in server/aiServer/providers/LLMProvider.ts: if a user supplies a custom baseURL without /v1 (or previously saved the default without /v1), strip any trailing slash and append /v1.
  3. Added unit tests in server/aiServer/providers/__tests__/anthropic-provider.test.ts covering baseURL normalization.

Fixes #1248

问题

在“设置 -> AI”中使用默认提供商模板配置 Anthropic 时,模板中 defaultBaseURL 默认填充为 https://api.anthropic.com。
@ai-sdk/anthropic 要求 baseURL 包含 API 版本前缀(其内部默认值为 https://api.anthropic.com/v1)。直接传入不含 /v1 的基础域名会覆盖此默认值,导致请求发送至 https://api.anthropic.com/messages 并返回 HTTP 404 Not Found。

解决方案

  1. 更新 app/src/components/BlinkoSettings/AiSetting/constants.tsx 中的 PROVIDER_TEMPLATES,将 defaultBaseURL 设置为 https://api.anthropic.com/v1(与 OpenAI 和 Voyage 模板一致)。
  2. 在 server/aiServer/providers/LLMProvider.ts 中增加兼容性处理:如果用户配置的 baseURL 未包含 /v1(或之前已保存未含 /v1 的地址),自动去除末尾斜杠并补全 /v1。
  3. 在 server/aiServer/providers/__tests__/anthropic-provider.test.ts 中新增覆盖 Anthropic baseURL 规范化逻辑的单元测试。

- Update Anthropic provider template defaultBaseURL to 'https://api.anthropic.com/v1'
- Normalize custom Anthropic baseURL in LLMProvider to append /v1 if missing
- Add unit tests for Anthropic baseURL normalization in LLMProvider

Co-authored-by: yalongwastaken <yalongwastaken@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Anthropic provider template Base URL missing /v1 — every request 404s

1 participant