You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an automated backport of #9229 to the release-v5.0 branch.
Co-authored-by: Daniel Hofheinz <daniel@danielhofheinz.com>
Co-authored-by: Nico Albanese <49612682+nicoalbanese@users.noreply.github.com>
Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
Anthropic language models can also be used in the `streamText`, `generateObject`, and `streamObject` functions
94
94
(see [AI SDK Core](/docs/ai-sdk-core)).
95
95
96
-
<Note>
97
-
The Anthropic API returns streaming tool calls all at once after a delay. This
98
-
causes the `streamObject` function to generate the object fully after a delay
99
-
instead of streaming it incrementally.
100
-
</Note>
96
+
### Structured Outputs and Tool Input Streaming
97
+
98
+
By default, the Anthropic API returns streaming tool calls and structured outputs all at once after a delay. To enable incremental streaming of tool inputs (when using `streamText` with tools) and structured outputs (when using `streamObject`), you need to set the `anthropic-beta` header to `fine-grained-tool-streaming-2025-05-14`.
99
+
100
+
#### For structured outputs with `streamObject`
101
+
102
+
```ts
103
+
import { anthropic } from'@ai-sdk/anthropic';
104
+
import { streamObject } from'ai';
105
+
import { z } from'zod';
106
+
107
+
const result =streamObject({
108
+
model: anthropic('claude-sonnet-4-20250514'),
109
+
schema: z.object({
110
+
characters: z.array(
111
+
z.object({
112
+
name: z.string(),
113
+
class: z.string(),
114
+
description: z.string(),
115
+
}),
116
+
),
117
+
}),
118
+
prompt: 'Generate 3 character descriptions for a fantasy role playing game.',
0 commit comments