WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2f5d2dc

Browse files
jherrautofix-ci[bot]AlemTuzlak
authored
Splitting adapters up fixes (#148)
* fixing JSON-Schema conversion * summarize now really supports streaming * ci: apply automated fixes * linting fixes * feat: add createOptions helper and improve summarization streaming - Add createOptions() function for type-safe adapter option creation - Refactor OpenAI summarize adapter to use text adapter for streaming - Deprecate textOptions() in favor of createOptions() - Update examples to use createOptions pattern - Add runtime adapter switching documentation guide * massive overhaul to remove ai * ci: apply automated fixes * Going to openaiText * ci: apply automated fixes * doc fixes and removal of legacy exports * adding more options to gemini audio * doc updates * ci: apply automated fixes * add docs script --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Alem Tuzlak <[email protected]>
1 parent 2b56f66 commit 2f5d2dc

File tree

161 files changed

+3774
-5413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+3774
-5413
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ The `chat()` method now includes an automatic tool execution loop:
369369

370370
```typescript
371371
import { chat, tool, maxIterations } from '@tanstack/ai'
372-
import { openai } from '@tanstack/ai-openai'
372+
import { openaiText } from '@tanstack/ai-openai'
373373

374374
const stream = chat({
375-
adapter: openai(),
375+
adapter: openaiText(),
376376
model: 'gpt-4o',
377377
messages: [{ role: 'user', content: "What's the weather in Paris?" }],
378378
tools: [weatherTool],

assets/CleanShot_2025-12-03_at_09.07.34_2x-e559659f-ceb7-4b86-879d-a603788b0b56.png

Whitespace-only changes.

docs/adapters/anthropic.md

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
2-
title: Anthropic Adapter
2+
title: Anthropic
33
id: anthropic-adapter
4+
order: 2
45
---
56

67
The Anthropic adapter provides access to Claude models, including Claude Sonnet 4.5, Claude Opus 4.5, and more.
@@ -14,72 +15,63 @@ npm install @tanstack/ai-anthropic
1415
## Basic Usage
1516

1617
```typescript
17-
import { ai } from "@tanstack/ai";
18+
import { chat } from "@tanstack/ai";
1819
import { anthropicText } from "@tanstack/ai-anthropic";
1920

2021
const adapter = anthropicText();
2122

22-
const stream = ai({
23+
const stream = chat({
2324
adapter,
25+
model: "claude-sonnet-4-5",
2426
messages: [{ role: "user", content: "Hello!" }],
25-
model: "claude-sonnet-4-5-20250929",
2627
});
2728
```
2829

2930
## Basic Usage - Custom API Key
3031

3132
```typescript
32-
import { ai } from "@tanstack/ai";
33-
import { createAnthropicText } from "@tanstack/ai-anthropic";
33+
import { chat } from "@tanstack/ai";
34+
import { createAnthropicChat } from "@tanstack/ai-anthropic";
3435

35-
const adapter = createAnthropicText(process.env.ANTHROPIC_API_KEY!, {
36+
const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, {
3637
// ... your config options
3738
});
3839

39-
const stream = ai({
40+
const stream = chat({
4041
adapter,
42+
model: "claude-sonnet-4-5",
4143
messages: [{ role: "user", content: "Hello!" }],
42-
model: "claude-sonnet-4-5-20250929",
4344
});
4445
```
4546

4647
## Configuration
4748

4849
```typescript
49-
import { createAnthropicText, type AnthropicTextConfig } from "@tanstack/ai-anthropic";
50+
import { createAnthropicChat, type AnthropicChatConfig } from "@tanstack/ai-anthropic";
5051

51-
const config: AnthropicTextConfig = {
52+
const config: Omit<AnthropicChatConfig, 'apiKey'> = {
5253
baseURL: "https://api.anthropic.com", // Optional, for custom endpoints
5354
};
5455

55-
const adapter = createAnthropicText(process.env.ANTHROPIC_API_KEY!, config);
56+
const adapter = createAnthropicChat(process.env.ANTHROPIC_API_KEY!, config);
5657
```
57-
58-
## Available Models
59-
60-
### Chat Models
61-
62-
- `claude-sonnet-4-5-20250929` - Claude Sonnet 4.5 (balanced)
63-
- `claude-opus-4-5-20251101` - Claude Opus 4.5 (most capable)
64-
- `claude-haiku-4-0-20250514` - Claude Haiku 4.0 (fastest)
65-
- `claude-3-5-sonnet-20241022` - Claude 3.5 Sonnet
66-
- `claude-3-opus-20240229` - Claude 3 Opus
58+
6759

6860
## Example: Chat Completion
6961

7062
```typescript
71-
import { ai, toStreamResponse } from "@tanstack/ai";
63+
import { chat, toStreamResponse } from "@tanstack/ai";
7264
import { anthropicText } from "@tanstack/ai-anthropic";
7365

7466
const adapter = anthropicText();
7567

7668
export async function POST(request: Request) {
7769
const { messages } = await request.json();
7870

79-
const stream = ai({
71+
const stream = chat({
8072
adapter,
73+
model: "claude-sonnet-4-5",
8174
messages,
82-
model: "claude-sonnet-4-5-20250929",
8375
});
8476

8577
return toStreamResponse(stream);
@@ -89,7 +81,7 @@ export async function POST(request: Request) {
8981
## Example: With Tools
9082

9183
```typescript
92-
import { ai, toolDefinition } from "@tanstack/ai";
84+
import { chat, toolDefinition } from "@tanstack/ai";
9385
import { anthropicText } from "@tanstack/ai-anthropic";
9486
import { z } from "zod";
9587

@@ -108,24 +100,24 @@ const searchDatabase = searchDatabaseDef.server(async ({ query }) => {
108100
return { results: [] };
109101
});
110102

111-
const stream = ai({
103+
const stream = chat({
112104
adapter,
105+
model: "claude-sonnet-4-5",
113106
messages,
114-
model: "claude-sonnet-4-5-20250929",
115107
tools: [searchDatabase],
116108
});
117109
```
118110

119-
## Provider Options
111+
## Model Options
120112

121113
Anthropic supports various provider-specific options:
122114

123115
```typescript
124-
const stream = ai({
116+
const stream = chat({
125117
adapter: anthropicText(),
118+
model: "claude-sonnet-4-5",
126119
messages,
127-
model: "claude-sonnet-4-5-20250929",
128-
providerOptions: {
120+
modelOptions: {
129121
max_tokens: 4096,
130122
temperature: 0.7,
131123
top_p: 0.9,
@@ -140,7 +132,7 @@ const stream = ai({
140132
Enable extended thinking with a token budget. This allows Claude to show its reasoning process, which is streamed as `thinking` chunks:
141133

142134
```typescript
143-
providerOptions: {
135+
modelOptions: {
144136
thinking: {
145137
type: "enabled",
146138
budget_tokens: 2048, // Maximum tokens for thinking
@@ -150,20 +142,14 @@ providerOptions: {
150142

151143
**Note:** `max_tokens` must be greater than `budget_tokens`. The adapter automatically adjusts `max_tokens` if needed.
152144

153-
**Supported Models:**
154-
155-
- `claude-sonnet-4-5-20250929` and newer
156-
- `claude-opus-4-5-20251101` and newer
157-
158-
When thinking is enabled, the model's reasoning process is streamed separately from the response text and appears as a collapsible thinking section in the UI.
159-
160145
### Prompt Caching
161146

162147
Cache prompts for better performance and reduced costs:
163148

164149
```typescript
165-
const stream = ai({
150+
const stream = chat({
166151
adapter: anthropicText(),
152+
model: "claude-sonnet-4-5",
167153
messages: [
168154
{
169155
role: "user",
@@ -180,7 +166,7 @@ const stream = ai({
180166
],
181167
},
182168
],
183-
model: "claude-sonnet-4-5-20250929",
169+
model: "claude-sonnet-4-5",
184170
});
185171
```
186172

@@ -189,14 +175,14 @@ const stream = ai({
189175
Anthropic supports text summarization:
190176

191177
```typescript
192-
import { ai } from "@tanstack/ai";
178+
import { summarize } from "@tanstack/ai";
193179
import { anthropicSummarize } from "@tanstack/ai-anthropic";
194180

195181
const adapter = anthropicSummarize();
196182

197-
const result = await ai({
183+
const result = await summarize({
198184
adapter,
199-
model: "claude-sonnet-4-5-20250929",
185+
model: "claude-sonnet-4-5",
200186
text: "Your long text to summarize...",
201187
maxLength: 100,
202188
style: "concise", // "concise" | "bullet-points" | "paragraph"
@@ -217,20 +203,20 @@ ANTHROPIC_API_KEY=sk-ant-...
217203

218204
### `anthropicText(config?)`
219205

220-
Creates an Anthropic text/chat adapter using environment variables.
206+
Creates an Anthropic chat adapter using environment variables.
221207

222-
**Returns:** An Anthropic text adapter instance.
208+
**Returns:** An Anthropic chat adapter instance.
223209

224-
### `createAnthropicText(apiKey, config?)`
210+
### `createAnthropicChat(apiKey, config?)`
225211

226-
Creates an Anthropic text/chat adapter with an explicit API key.
212+
Creates an Anthropic chat adapter with an explicit API key.
227213

228214
**Parameters:**
229215

230216
- `apiKey` - Your Anthropic API key
231217
- `config.baseURL?` - Custom base URL (optional)
232218

233-
**Returns:** An Anthropic text adapter instance.
219+
**Returns:** An Anthropic chat adapter instance.
234220

235221
### `anthropicSummarize(config?)`
236222

0 commit comments

Comments
 (0)