fix: add missing Anthropic models type and update the anthropic docs#234
fix: add missing Anthropic models type and update the anthropic docs#234fuadnafiz98 wants to merge 3 commits intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughExports a new public type Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 markdownlint-cli2 (0.18.1).changeset/add-anthropic-models-export.mdmarkdownlint-cli2 v0.18.1 (markdownlint v0.38.0) docs/adapters/anthropic.mdmarkdownlint-cli2 v0.18.1 (markdownlint v0.38.0) 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
docs/adapters/anthropic.md (2)
46-54: Configuration example uses outdated function signature.This example still uses the old
createAnthropicChat(apiKey, config)signature, but the breaking change requires the model as the first parameter:createAnthropicChat(model, apiKey, config).Proposed fix
## Configuration ```typescript import { createAnthropicChat, type AnthropicChatConfig } from "@tanstack/ai-anthropic"; const config: Omit<AnthropicChatConfig, 'apiKey'> = { baseURL: "https://api.anthropic.com", // Optional, for custom endpoints }; -const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, config); +const adapter = createAnthropicChat("claude-sonnet-4-5", process.env.ANTHROPIC_API_KEY!, config);</details> --- `195-204`: **API reference doesn't reflect the new function signature.** The `createAnthropicChat` documentation still shows the old signature `(apiKey, config?)`. Update it to reflect the breaking change where model is the first parameter. <details> <summary>Proposed fix</summary> ```diff ### `createAnthropicChat(apiKey, config?)` +### `createAnthropicChat(model, apiKey, config?)` Creates an Anthropic chat adapter with an explicit API key. **Parameters:** +- `model` - The Anthropic model identifier (e.g., `'claude-sonnet-4-5'`) - `apiKey` - Your Anthropic API key - `config.baseURL?` - Custom base URL (optional) **Returns:** An Anthropic chat adapter instance.
🤖 Fix all issues with AI agents
In @.changeset/add-anthropic-models-export.md:
- Around line 1-3: The changeset is incorrectly marked as 'minor' despite
introducing a breaking change to the createAnthropicChat function signature
(model is now the first parameter); update the changeset entry in
.changeset/add-anthropic-models-export.md to use a 'major' release type so
semantic versioning reflects the breaking change and consumers are notified of
the API change.
- Around line 37-49: The adapter function currently types its parameter as
ANTHROPIC_MODELS (a tuple) which requires the whole tuple instead of a single
model string; update the parameter type to ANTHROPIC_MODELS[number] so
adapter(model: ANTHROPIC_MODELS[number]) and the call
adapter('claude-sonnet-4-5') are type-correct, or alternatively export a union
alias (e.g., type AnthropicModel = ANTHROPIC_MODELS[number]) and use that in
adapter and any createAnthropicChat/chat calls to improve ergonomics.
In `@docs/adapters/anthropic.md`:
- Around line 33-36: The adapter function parameter currently uses the aggregate
type ANTHROPIC_MODELS; change its parameter type to the element type
ANTHROPIC_MODELS[number] so the adapter(model: ANTHROPIC_MODELS[number]) accepts
a single model string; update the adapter declaration that calls
createAnthropicChat (and any other usages of adapter) to use
ANTHROPIC_MODELS[number] as the parameter type.
| const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, { | ||
| // ... your config options | ||
| }); | ||
| const adapter = (model: AnthropicModels) => |
There was a problem hiding this comment.
revert this change please
There was a problem hiding this comment.
Hi,
Thanks for your review.
Correct me if I am wrong, but when I was trying to use createAnthropicChat it gives me errors as of the previous docs example. When I see the function definition here I can see that it requires the model in the first parameter.
There was a problem hiding this comment.
If that is the case then shouldn't the docs be updated?
There was a problem hiding this comment.
that is true but it should be:
const adapter = createAnthropicChat("model", process.env.ANTHROPIC_API_KEY!, {...})There was a problem hiding this comment.
Hi,
About the example, we can either put the example like this:
import { chat } from '@tanstack/ai'
import { createAnthropicChat } from '@tanstack/ai-anthropic'
const adapter = createAnthropicChat(
'claude-sonnet-4-5',
process.env.ANTHROPIC_API_KEY!,
{
// ... your config options
},
)
const stream = chat({
adapter: adapter,
messages: [{ role: 'user', content: 'Hello!' }],
})here the adapter is connected with a single model and we pass it to the chat, but in the other examples in the docs I can see we can change the model names in the chat so its more flexible to try out different model.
So if we put the example like this:
const adapter = (model: AnthropicModels) =>
createAnthropicChat(model, process.env.ANTHROPIC_API_KEY!, {
// ... your config options
})
const stream = chat({
adapter: adapter('claude-3-5-haiku'),
messages: [{ role: 'user', content: 'Hello!' }],
})We can easily swap out different models in the chat like this:
Let me know what do you think and if I am thinking in a wrong way 🙏
There was a problem hiding this comment.
Hello @AlemTuzlak can you please have a look
Thanks.
|
|
||
| The type ensures only valid Anthropic model identifiers can be passed, preventing runtime errors. | ||
|
|
||
| ### Breaking Change |
There was a problem hiding this comment.
remove the breaking change section as it's not a breaking change
| @@ -0,0 +1,64 @@ | |||
| --- | |||
| '@tanstack/ai-anthropic': major | |||
There was a problem hiding this comment.
this is not a major change, this hsould be set to patch
🎯 Changes
WHAT
Added missing
ANTHROPIC_MODELStype export to the public API of@tanstack/ai-anthropicand updated the documentation to correctly reference it.The
ANTHROPIC_MODELSis a const tuple that contains all supported Anthropic model identifiers:WHY
When I tried to use the
createAnthropicChataccording to the docs it gave me type errors and I find out that the first parameter it takes is the model name, not the API KEY as the docs suggest.Then I find out that there is actually a type
ANTHROPIC_MODELSwhich is not exported that I can use to construct the adapter.HOW - Consumers Should Update
Now you can import and use
ANTHROPIC_MODELSfor proper type safety when creating adapter instances:✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Breaking Changes
New Features
✏️ Tip: You can customize this high-level summary in your review settings.