Skip to content

fix: use @ai-sdk/anthropic provider so ANTHROPIC_API_KEY works as documented - #1

Open
erhnysr wants to merge 1 commit into
RitualChain:mainfrom
erhnysr:fix/anthropic-provider-api-key
Open

fix: use @ai-sdk/anthropic provider so ANTHROPIC_API_KEY works as documented#1
erhnysr wants to merge 1 commit into
RitualChain:mainfrom
erhnysr:fix/anthropic-provider-api-key

Conversation

@erhnysr

@erhnysr erhnysr commented Jul 25, 2026

Copy link
Copy Markdown

What this fixes

Following the README's own local setup instructions currently breaks every AI feature.

The README, .env.example, and the Vercel deploy button all tell you to provide ANTHROPIC_API_KEY. But both API routes reference the model as a bare string:

model: "anthropic/claude-sonnet-4-20250514"

In AI SDK v6, a bare-string model is resolved through the Vercel AI Gateway, which authenticates via AI_GATEWAY_API_KEY (or Vercel OIDC) and never reads ANTHROPIC_API_KEY. There is no @ai-sdk/anthropic dependency in the project, so the documented key has nothing to bind to.

Result: a developer who does exactly what the README says (cp .env.example .env.local, set ANTHROPIC_API_KEY, bun dev) gets an auth failure on every request:

Unauthenticated request to AI Gateway.
To authenticate, set the AI_GATEWAY_API_KEY environment variable with your API key.
Alternatively, you can use a provider module instead of the AI Gateway.

The fix

Add @ai-sdk/anthropic and use the provider module, which reads ANTHROPIC_API_KEY from the environment by default — matching the documented setup:

import { anthropic } from "@ai-sdk/anthropic"
// ...
model: anthropic("claude-sonnet-4-20250514")

Applied to both routes: app/api/agent/route.ts and app/api/agent/generate/route.ts.

The AI SDK's own gateway error even points at this exact remedy ("use a provider module instead of the AI Gateway").

Why this matches the intended setup

No docs change is needed — this makes the code honor the ANTHROPIC_API_KEY that the README and .env.example already document. The provider is pinned to @ai-sdk/anthropic@^3.0.102 (the package's ai-v6 release line) so it's spec-compatible with the pinned ai@6.0.37; the newer 4.x line targets a different AI SDK major and fails type-checking here.

Verification (local, per the README)

Set only ANTHROPIC_API_KEY in .env.local, bun dev, then POST /api/agent/generate:

Model reference Server-side result
Before "anthropic/claude-sonnet-4-20250514" Unauthenticated request to AI GatewayANTHROPIC_API_KEY ignored
After anthropic("claude-sonnet-4-20250514") request reaches Anthropic and uses the key as x-api-key (a real key returns a completion; a dummy key returns Anthropic's invalid x-api-key)

Also verified:

  • bunx tsc --noEmit — clean
  • bun run build — compiles successfully; both /api/agent and /api/agent/generate build as dynamic routes

Scope

Minimal: two one-line model changes + their import, one dependency, and the lockfile. No behavior change beyond authentication; system prompts, tools, validation, and rate limiting are untouched.

The API routes referenced the model as the bare string
"anthropic/claude-sonnet-4-20250514". In AI SDK v6 a bare string model
is resolved through the Vercel AI Gateway, which authenticates via
AI_GATEWAY_API_KEY (or Vercel OIDC) and never reads ANTHROPIC_API_KEY.

Following the README locally (set ANTHROPIC_API_KEY, run bun dev) therefore
failed every AI feature with 'Unauthenticated request to AI Gateway'.

Add @ai-sdk/anthropic and use anthropic("claude-sonnet-4-20250514") so the
routes read ANTHROPIC_API_KEY exactly as the README and .env.example document.
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@erhnysr is attempting to deploy a commit to the 0xBuns Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant