Repository navigation
feat(ai-anthropic): choose the credential kind with auth, and read the environment only in anthropicText - #1688
Conversation
…vironment only in anthropicText
createAnthropicChat, createAnthropicSummarize, and createAnthropicFiles take the
credential as an argument and read no credential from the environment. The new
auth option ('api-key' | 'bearer' | 'oauth') sets how the credential goes out.
The default is 'oauth' for an sk-ant-oat credential, else 'api-key'.
anthropicText, anthropicSummarize, and anthropicFiles read ANTHROPIC_AUTH_TOKEN,
then ANTHROPIC_OAUTH_TOKEN, then ANTHROPIC_API_KEY, and throw when none is set.
A config auth wins over the detected kind.
The authToken and oauth config fields are removed.
|
| Name | Type |
|---|---|
| @tanstack/ai-anthropic | Minor |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughAnthropic authentication now uses explicit ChangesAnthropic authentication
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant anthropicText
participant getAnthropicCredentialFromEnv
participant createAnthropicChat
participant createAnthropicClient
anthropicText->>getAnthropicCredentialFromEnv: Read credential and detected auth
anthropicText->>createAnthropicChat: Pass credential and selected auth
createAnthropicChat->>createAnthropicClient: Create client with credential and auth
Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable issue remains that should prevent merging after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)Full details: Docstring CoverageExplanation Docstring coverage is 78.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 7 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 4387263
☁️ Nx Cloud last updated this comment at |
Coverage✅ Coverage held across 2 compared package(s). Each package is measured twice in this job — on this PR and on its merge-base with
|
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-byteplus
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-cloudflare
@tanstack/ai-code-mode
@tanstack/ai-code-mode-snippets
@tanstack/ai-codex
@tanstack/ai-cohere
@tanstack/ai-compaction
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-daytona
@tanstack/ai-isolate-e2b
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-isolate-quickjs-bun
@tanstack/ai-llmgateway
@tanstack/ai-lovable
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-octane
@tanstack/ai-ollama
@tanstack/ai-ollaya
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-perplexity
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-reactor
@tanstack/ai-remix
@tanstack/ai-sandbox
@tanstack/ai-sandbox-blaxel
@tanstack/ai-sandbox-boxd
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-e2b
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-railway
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-upstash-box
@tanstack/ai-sandbox-vercel
@tanstack/ai-skills
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-typesafe
@tanstack/ai-utils
@tanstack/ai-vercel-gateway
@tanstack/ai-vertex
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/ai-worldlabs
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
@tanstack/svelte-ai-devtools
commit: |
The Anthropic adapters now follow the same factory pattern as every other adapter.
createAnthropicChat(model, credential, config?)reads nothing from the environment, andanthropicText(model, config?)reads the credential from the environment. #1679 had mixed the two: the client readANTHROPIC_*by itself, andanthropicTexttook credentials in its config. #1679 is not released yet, so this PR changes its API before anyone uses it.🎯 Changes
auth?: 'api-key' | 'bearer' | 'oauth'option replaces theauthTokenandoauthoptions from feat(ai-anthropic): support Bearer tokens and Claude OAuth tokens #1679:'oauth'when the credential containssk-ant-oat, else'api-key'.'bearer'and'oauth'sendAuthorization: Bearerand nox-api-key.'oauth'also adds the Claude Code identity, headers, and betas. That logic is unchanged from feat(ai-anthropic): support Bearer tokens and Claude OAuth tokens #1679.createAnthropicChat,createAnthropicSummarize, andcreateAnthropicFilestake the credential as an argument, andapiKeyis a requiredstringagain.nulls, so the Anthropic SDK does not readANTHROPIC_API_KEYorANTHROPIC_AUTH_TOKENby itself.anthropicText,anthropicSummarize, andanthropicFilesread the credential with one helper,getAnthropicCredentialFromEnv(), fromwindow.envorprocess.env. The order isANTHROPIC_AUTH_TOKEN, thenANTHROPIC_OAUTH_TOKEN, thenANTHROPIC_API_KEY. They throw when none is set. Their config has noapiKey. A configauthwins over the detected kind.resolveAnthropicCredentialsand the internalgetAnthropicApiKeyFromEnvare removed. Neither was a public export.adapters/anthropic.md, plus line 21 ofadvanced/files-api.md..changeset/anthropic-bearer-oauth.mdfrom feat(ai-anthropic): support Bearer tokens and Claude OAuth tokens #1679 is rewritten for the final API. There is no second changeset.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.🚀 Release Impact
Testing
Commands run
vitest runinpackages/ai-anthropic, after the merge withmain(8caa6b0d): 216 tests pass.tests/auth-parity.test.tsnow has 22 tests.test:types,test:oxlint, and knip forai-anthropic: clean.pnpm test:docs: no broken links.kiira checkon the two pages: 30 snippets pass.tscontesting/e2e: no errors in the changed files.pnpm test:prand the E2E suite. CI runs them.Manual test
pnpm --dir packages/ai-anthropic exec vitest run tests/auth-parity.test.ts.createAnthropicChatsendsx-api-keywith the explicit key even whenANTHROPIC_AUTH_TOKENis set.auth: 'bearer'sendsAuthorization: Bearer.sk-ant-oattoken turns on OAuth.authwins over detection.anthropicTextfollows the env order and throws when nothing is set.@ts-expect-errorlines rejectapiKeyon the env factories, and they show thatauthTokenandoauthare gone.How this PR makes testing easy
anthropic-auth-wire.spec.tsand its route now usecreateAnthropicChatwithauth: 'api-key' | 'bearer' | 'oauth'.Risk / rollback
ANTHROPIC_API_KEYthat holds ansk-ant-oatvalue is now sent as an API key, not detected as OAuth. UseANTHROPIC_OAUTH_TOKENorauth: 'oauth'for that.wrapFetch) both change the Anthropic adapter constructor. The one that merges second needs a small merge.To undo, revert this PR.
Public API change
Before (#1679 on
main, not released)After
Summary by CodeRabbit
ANTHROPIC_AUTH_TOKEN,ANTHROPIC_OAUTH_TOKEN, thenANTHROPIC_API_KEY. They report an error if no credential is available; direct factory integrations use the credential you provide.