From c180ea6b85d24a1f30cf95dd7ed4409bdb293db1 Mon Sep 17 00:00:00 2001 From: fuadnafiz98 Date: Sun, 18 Jan 2026 12:30:00 +0600 Subject: [PATCH 1/3] fix: add missing ANTHROPIC_MODELS type and update the anthropic docs --- docs/adapters/anthropic.md | 11 ++++++----- packages/typescript/ai-anthropic/src/index.ts | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/adapters/anthropic.md b/docs/adapters/anthropic.md index 15fd179f..f3d5985e 100644 --- a/docs/adapters/anthropic.md +++ b/docs/adapters/anthropic.md @@ -28,11 +28,12 @@ const stream = chat({ ```typescript import { chat } from "@tanstack/ai"; -import { createAnthropicChat } from "@tanstack/ai-anthropic"; +import { createAnthropicChat, ANTHROPIC_MODELS } from "@tanstack/ai-anthropic"; -const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, { - // ... your config options -}); +const adapter = (model: ANTHROPIC_MODELS) => + 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 = { const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, config); ``` - + ## Example: Chat Completion diff --git a/packages/typescript/ai-anthropic/src/index.ts b/packages/typescript/ai-anthropic/src/index.ts index 4bca2e4b..15a66634 100644 --- a/packages/typescript/ai-anthropic/src/index.ts +++ b/packages/typescript/ai-anthropic/src/index.ts @@ -27,6 +27,7 @@ export { export type { AnthropicChatModelProviderOptionsByName, AnthropicModelInputModalitiesByName, + ANTHROPIC_MODELS } from './model-meta' export type { AnthropicTextMetadata, From 5e23d1fc38f1554ddd8f7f4fc3175816bea38d44 Mon Sep 17 00:00:00 2001 From: fuadnafiz98 Date: Sun, 18 Jan 2026 12:44:32 +0600 Subject: [PATCH 2/3] chore: added changeset --- .changeset/add-anthropic-models-export.md | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .changeset/add-anthropic-models-export.md diff --git a/.changeset/add-anthropic-models-export.md b/.changeset/add-anthropic-models-export.md new file mode 100644 index 00000000..7ce06019 --- /dev/null +++ b/.changeset/add-anthropic-models-export.md @@ -0,0 +1,75 @@ +--- +'@tanstack/ai-anthropic': minor +--- + +## Add missing ANTHROPIC_MODELS type export + +### WHAT + +Added missing `ANTHROPIC_MODELS` type export to the public API of `@tanstack/ai-anthropic` and updated the documentation to correctly reference it. + +The `ANTHROPIC_MODELS` is a const tuple that contains all supported Anthropic model identifiers: + +```typescript +type ANTHROPIC_MODELS = readonly [ + 'claude-opus-4-5', + 'claude-sonnet-4-5', + 'claude-haiku-4-5', + 'claude-opus-4-1', + 'claude-sonnet-4', + 'claude-sonnet-3-7', + 'claude-opus-4', + 'claude-haiku-3-5', + 'claude-haiku-3', +] +``` + +### WHY + +The `ANTHROPIC_MODELS` type was already used internally and in the model metadata but was not exported from the main package entry point. This prevented consumers from using it for type-safe model selection when creating custom adapter instances, resulting in incomplete TypeScript support and requiring workarounds like manual type assertions. + +By exporting this type, consumers now have full type safety when working with Anthropic models and can write more maintainable code. + +### HOW - Consumers Should Update + +Now you can import and use `ANTHROPIC_MODELS` for proper type safety when creating adapter instances: + +```typescript +import { createAnthropicChat, ANTHROPIC_MODELS } from '@tanstack/ai-anthropic' + +const adapter = (model: ANTHROPIC_MODELS) => + 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 + +`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 + }, +) +``` From 8c495430b42193d28e31ffd108c0687cac252da5 Mon Sep 17 00:00:00 2001 From: fuadnafiz98 Date: Sun, 18 Jan 2026 13:38:55 +0600 Subject: [PATCH 3/3] fix: update the export type for anthropic models and update docs --- .changeset/add-anthropic-models-export.md | 33 +++++++------------ docs/adapters/anthropic.md | 4 +-- packages/typescript/ai-anthropic/src/index.ts | 2 +- .../typescript/ai-anthropic/src/model-meta.ts | 2 ++ 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/.changeset/add-anthropic-models-export.md b/.changeset/add-anthropic-models-export.md index 7ce06019..f9df4019 100644 --- a/.changeset/add-anthropic-models-export.md +++ b/.changeset/add-anthropic-models-export.md @@ -1,43 +1,32 @@ --- -'@tanstack/ai-anthropic': minor +'@tanstack/ai-anthropic': major --- -## Add missing ANTHROPIC_MODELS type export +## Add missing AnthropicModels type export ### WHAT -Added missing `ANTHROPIC_MODELS` type export to the public API of `@tanstack/ai-anthropic` and updated the documentation to correctly reference it. - -The `ANTHROPIC_MODELS` is a const tuple that contains all supported Anthropic model identifiers: +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 -type ANTHROPIC_MODELS = readonly [ - 'claude-opus-4-5', - 'claude-sonnet-4-5', - 'claude-haiku-4-5', - 'claude-opus-4-1', - 'claude-sonnet-4', - 'claude-sonnet-3-7', - 'claude-opus-4', - 'claude-haiku-3-5', - 'claude-haiku-3', -] +export type AnthropicModels = (typeof ANTHROPIC_MODELS)[number] +// Equivalent to: 'claude-opus-4-5' | 'claude-sonnet-4-5' | 'claude-haiku-4-5' | ... (and more) ``` -### WHY +**Note:** The `ANTHROPIC_MODELS` const tuple itself remains internal and is not exported. Only the derived type is part of the public API. -The `ANTHROPIC_MODELS` type was already used internally and in the model metadata but was not exported from the main package entry point. This prevented consumers from using it for type-safe model selection when creating custom adapter instances, resulting in incomplete TypeScript support and requiring workarounds like manual type assertions. +### WHY -By exporting this type, consumers now have full type safety when working with Anthropic models and can write more maintainable code. +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 `ANTHROPIC_MODELS` for proper type safety when creating adapter instances: +Now you can import and use `AnthropicModels` for proper type safety when creating adapter instances: ```typescript -import { createAnthropicChat, ANTHROPIC_MODELS } from '@tanstack/ai-anthropic' +import { createAnthropicChat, AnthropicModels } from '@tanstack/ai-anthropic' -const adapter = (model: ANTHROPIC_MODELS) => +const adapter = (model: AnthropicModels) => createAnthropicChat(model, process.env.ANTHROPIC_API_KEY!, { // ... your config options }) diff --git a/docs/adapters/anthropic.md b/docs/adapters/anthropic.md index f3d5985e..b0bfbd79 100644 --- a/docs/adapters/anthropic.md +++ b/docs/adapters/anthropic.md @@ -28,9 +28,9 @@ const stream = chat({ ```typescript import { chat } from "@tanstack/ai"; -import { createAnthropicChat, ANTHROPIC_MODELS } from "@tanstack/ai-anthropic"; +import { createAnthropicChat, AnthropicModels } from "@tanstack/ai-anthropic"; -const adapter = (model: ANTHROPIC_MODELS) => +const adapter = (model: AnthropicModels) => createAnthropicChat(model, process.env.ANTHROPIC_API_KEY!, { // ... your config options }); diff --git a/packages/typescript/ai-anthropic/src/index.ts b/packages/typescript/ai-anthropic/src/index.ts index 15a66634..fdf8b1b4 100644 --- a/packages/typescript/ai-anthropic/src/index.ts +++ b/packages/typescript/ai-anthropic/src/index.ts @@ -27,7 +27,7 @@ export { export type { AnthropicChatModelProviderOptionsByName, AnthropicModelInputModalitiesByName, - ANTHROPIC_MODELS + AnthropicModels, } from './model-meta' export type { AnthropicTextMetadata, diff --git a/packages/typescript/ai-anthropic/src/model-meta.ts b/packages/typescript/ai-anthropic/src/model-meta.ts index fa48e503..124b98eb 100644 --- a/packages/typescript/ai-anthropic/src/model-meta.ts +++ b/packages/typescript/ai-anthropic/src/model-meta.ts @@ -372,6 +372,8 @@ export const ANTHROPIC_MODELS = [ CLAUDE_HAIKU_3.id, ] as const +export type AnthropicModels = (typeof ANTHROPIC_MODELS)[number] + // const ANTHROPIC_IMAGE_MODELS = [] as const // const ANTHROPIC_EMBEDDING_MODELS = [] as const // const ANTHROPIC_AUDIO_MODELS = [] as const