-
-
Notifications
You must be signed in to change notification settings - Fork 116
fix: add missing Anthropic models type and update the anthropic docs #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| '@tanstack/ai-anthropic': major | ||
| --- | ||
|
|
||
| ## Add missing AnthropicModels type export | ||
|
|
||
| ### WHAT | ||
|
|
||
| Added new `AnthropicModels` **type** export to the public API of `@tanstack/ai-anthropic`. This is a union type that represents all supported Anthropic model identifiers, derived from the internal `ANTHROPIC_MODELS` const tuple. | ||
|
|
||
| ```typescript | ||
| export type AnthropicModels = (typeof ANTHROPIC_MODELS)[number] | ||
| // Equivalent to: 'claude-opus-4-5' | 'claude-sonnet-4-5' | 'claude-haiku-4-5' | ... (and more) | ||
| ``` | ||
| **Note:** The `ANTHROPIC_MODELS` const tuple itself remains internal and is not exported. Only the derived type is part of the public API. | ||
| ### WHY | ||
| Consumers previously had no easy way to get the type-safe union of model names for use in function signatures and variable declarations. | ||
| ### HOW - Consumers Should Update | ||
| Now you can import and use `AnthropicModels` for proper type safety when creating adapter instances: | ||
| ```typescript | ||
| import { createAnthropicChat, AnthropicModels } from '@tanstack/ai-anthropic' | ||
|
|
||
| const adapter = (model: AnthropicModels) => | ||
| createAnthropicChat(model, process.env.ANTHROPIC_API_KEY!, { | ||
| // ... your config options | ||
| }) | ||
|
|
||
| const stream = chat({ | ||
| adapter: adapter('claude-sonnet-4-5'), // Type-checked model selection! | ||
| messages: [{ role: 'user', content: 'Hello!' }], | ||
| }) | ||
| ``` | ||
|
|
||
| The type ensures only valid Anthropic model identifiers can be passed, preventing runtime errors. | ||
|
|
||
| ### Breaking Change | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the breaking change section as it's not a breaking change |
||
|
|
||
| `createAnthropicChat` now requires the model as the first parameter. If you were calling it without a model parameter, you must update your code: | ||
|
|
||
| **Before:** | ||
|
|
||
| ```typescript | ||
| const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, { | ||
| // ... config | ||
| }) | ||
| ``` | ||
|
|
||
| **After:** | ||
|
|
||
| ```typescript | ||
| const adapter = createAnthropicChat( | ||
| 'claude-sonnet-4-5', | ||
| process.env.ANTHROPIC_API_KEY!, | ||
| { | ||
| // ... config | ||
| }, | ||
| ) | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,11 +28,12 @@ const stream = chat({ | |
|
|
||
| ```typescript | ||
| import { chat } from "@tanstack/ai"; | ||
| import { createAnthropicChat } from "@tanstack/ai-anthropic"; | ||
| import { createAnthropicChat, AnthropicModels } from "@tanstack/ai-anthropic"; | ||
|
|
||
| const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, { | ||
| // ... your config options | ||
| }); | ||
| const adapter = (model: AnthropicModels) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this change please
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, Correct me if I am wrong, but when I was trying to use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that is the case then shouldn't the docs be updated?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is true but it should be: const adapter = createAnthropicChat("model", process.env.ANTHROPIC_API_KEY!, {...})
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, 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 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 🙏 |
||
| createAnthropicChat(model, process.env.ANTHROPIC_API_KEY!, { | ||
| // ... your config options | ||
| }); | ||
|
|
||
| const stream = chat({ | ||
| adapter: adapter("claude-sonnet-4-5"), | ||
|
|
@@ -51,7 +52,7 @@ const config: Omit<AnthropicChatConfig, 'apiKey'> = { | |
|
|
||
| const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, config); | ||
| ``` | ||
|
|
||
|
|
||
| ## Example: Chat Completion | ||
|
|
||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a major change, this hsould be set to patch