Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .changeset/add-anthropic-models-export.md
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

`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
},
)
```
11 changes: 6 additions & 5 deletions docs/adapters/anthropic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
createAnthropicChat(model, process.env.ANTHROPIC_API_KEY!, {
// ... your config options
});

const stream = chat({
adapter: adapter("claude-sonnet-4-5"),
Expand All @@ -51,7 +52,7 @@ const config: Omit<AnthropicChatConfig, 'apiKey'> = {

const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, config);
```


## Example: Chat Completion

Expand Down
1 change: 1 addition & 0 deletions packages/typescript/ai-anthropic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
export type {
AnthropicChatModelProviderOptionsByName,
AnthropicModelInputModalitiesByName,
AnthropicModels,
} from './model-meta'
export type {
AnthropicTextMetadata,
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript/ai-anthropic/src/model-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down