Skip to content

Conversation

@fuadnafiz98
Copy link

@fuadnafiz98 fuadnafiz98 commented Jan 18, 2026

🎯 Changes

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:

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

When I tried to use the createAnthropicChat according 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_MODELS which is not exported that I can use to construct the adapter.

HOW - Consumers Should Update

Now you can import and use ANTHROPIC_MODELS for proper type safety when creating adapter instances:

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!' }],
})

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Breaking Changes

    • The Anthropic adapter factory now requires the model identifier as the first argument when creating an instance.
  • New Features

    • Public, type-safe export for Anthropic model identifiers.
    • Adapter usage updated to support runtime model selection with improved type safety.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

Exports a new public type AnthropicModels and updates createAnthropicChat to require the model as the first argument (createAnthropicChat(model, apiKey, config?)), updating docs and examples to use a model-aware adapter factory. This is a breaking change.

Changes

Cohort / File(s) Summary
Changeset Documentation
\.changeset/add-anthropic-models-export.md
Adds changeset documenting the new AnthropicModels export and the breaking API change: createAnthropicChat now takes model as the first parameter instead of the API key.
Public API / Types
packages/typescript/ai-anthropic/src/model-meta.ts, packages/typescript/ai-anthropic/src/index.ts
Adds and exports AnthropicModels as export type AnthropicModels = (typeof ANTHROPIC_MODELS)[number]; updates public exports to include this type.
Adapter Documentation
docs/adapters/anthropic.md
Updates examples and docs to import AnthropicModels and show adapter usage as a model-aware factory (e.g., adapter("claude-sonnet-4-5")) reflecting the new createAnthropicChat(model, apiKey, config?) signature.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • harry-whorlow

Poem

🐰 I hopped in with keys and hops anew,
I plucked a model first — then API too.
Claude or sonnet, picked with care,
Type-safe choices floating on air.
🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding a missing Anthropic models type export and updating documentation to reflect the new API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.md

markdownlint-cli2 v0.18.1 (markdownlint v0.38.0)
Finding: .changeset/add-anthropic-models-export.md
Linting: 1 file(s)
Summary: 0 error(s)
Error: EACCES: permission denied, open '/markdownlint-cli2-results.json'
at async open (node:internal/fs/promises:640:25)
at async Object.writeFile (node:internal/fs/promises:1214:14)
at async Promise.all (index 0)
at async outputSummary (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:877:5)
at async main (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:1053:25)
at async file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2-bin.mjs:12:22 {
errno: -13,
code: 'EACCES',
syscall: 'open',
path: '/markdownlint-cli2-results.json'
}

docs/adapters/anthropic.md

markdownlint-cli2 v0.18.1 (markdownlint v0.38.0)
Finding: docs/adapters/anthropic.md
Linting: 1 file(s)
Summary: 0 error(s)
Error: EACCES: permission denied, open '/markdownlint-cli2-results.json'
at async open (node:internal/fs/promises:640:25)
at async Object.writeFile (node:internal/fs/promises:1214:14)
at async Promise.all (index 0)
at async outputSummary (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:877:5)
at async main (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:1053:25)
at async file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2-bin.mjs:12:22 {
errno: -13,
code: 'EACCES',
syscall: 'open',
path: '/markdownlint-cli2-results.json'
}


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fuadnafiz98 fuadnafiz98 changed the title fix: add missing ANTHROPIC_MODELS type and update the anthropic docs fix: add missing Anthropic models type and update the anthropic docs Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant