fix: use @ai-sdk/anthropic provider so ANTHROPIC_API_KEY works as documented - #1
Open
erhnysr wants to merge 1 commit into
Open
fix: use @ai-sdk/anthropic provider so ANTHROPIC_API_KEY works as documented#1erhnysr wants to merge 1 commit into
erhnysr wants to merge 1 commit into
Conversation
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.
|
@erhnysr is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 provideANTHROPIC_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 readsANTHROPIC_API_KEY. There is no@ai-sdk/anthropicdependency 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, setANTHROPIC_API_KEY,bun dev) gets an auth failure on every request:The fix
Add
@ai-sdk/anthropicand use the provider module, which readsANTHROPIC_API_KEYfrom the environment by default — matching the documented setup:Applied to both routes:
app/api/agent/route.tsandapp/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_KEYthat the README and.env.examplealready document. The provider is pinned to@ai-sdk/anthropic@^3.0.102(the package'sai-v6release line) so it's spec-compatible with the pinnedai@6.0.37; the newer4.xline targets a different AI SDK major and fails type-checking here.Verification (local, per the README)
Set only
ANTHROPIC_API_KEYin.env.local,bun dev, thenPOST /api/agent/generate:"anthropic/claude-sonnet-4-20250514"Unauthenticated request to AI Gateway—ANTHROPIC_API_KEYignoredanthropic("claude-sonnet-4-20250514")x-api-key(a real key returns a completion; a dummy key returns Anthropic'sinvalid x-api-key)Also verified:
bunx tsc --noEmit— cleanbun run build— compiles successfully; both/api/agentand/api/agent/generatebuild as dynamic routesScope
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.