Skip to content

fix(models): normalize bare-host ANTHROPIC_BASE_URL in getAnthropicProvider#62

Open
slusset wants to merge 1 commit into
bug0inc:mainfrom
slusset:fix/anthropic-base-url-normalization
Open

fix(models): normalize bare-host ANTHROPIC_BASE_URL in getAnthropicProvider#62
slusset wants to merge 1 commit into
bug0inc:mainfrom
slusset:fix/anthropic-base-url-normalization

Conversation

@slusset

@slusset slusset commented Jun 17, 2026

Copy link
Copy Markdown

Fixes #57.

Problem. AI coding harnesses (Claude Code, Cursor) export ANTHROPIC_BASE_URL as a bare host (https://api.anthropic.com, no /v1). @ai-sdk/anthropic prefers this env var over its …/v1 default, so getAnthropicProvider()'s createAnthropic({ apiKey }) (no baseURL) inherits the bare host and every Anthropic request 404s at …/messages. Gemini keeps working, so consensus runs look half-broken with nothing pointing at the env var.

Fix. Normalize the env value (append /v1 when it lacks a version path) and pass it explicitly as baseURL. Unset env → undefined, so the provider keeps its own default. Scoped to the direct path; the gateway path already sets baseURL.

Tests. New src/__tests__/models.test.ts covers bare host, trailing slash, already-/v1, /v1/, custom proxy, and unset. pnpm build / lint / test (172) green.

Upstream SDK issue: vercel/ai#15542.

…ovider

AI coding harnesses (Claude Code, Cursor) export ANTHROPIC_BASE_URL as a
bare host (https://api.anthropic.com, no /v1) for their own runtime.
@ai-sdk/anthropic prefers this env var over its https://api.anthropic.com/v1
default and uses it verbatim, so getAnthropicProvider()'s createAnthropic({
apiKey }) call (no baseURL) silently inherits the bare host and every
Anthropic request 404s at .../messages. Other providers (e.g. Gemini) keep
working, so consensus runs look half-broken with nothing pointing at the env.

Normalize the env value (append /v1 when it lacks a version path) and pass it
explicitly as baseURL. Unset env returns undefined so the provider keeps its
own default. Scoped to the direct path; the gateway path already sets baseURL.

Closes bug0inc#57. See vercel/ai#15542 for the upstream SDK issue.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 assertions 404 when ANTHROPIC_BASE_URL is set as a bare host (Claude Code / Cursor environments)

1 participant