Skip to content

Commit a85c85f

Browse files
authored
fix (provider/anthropic): streaming json output (#6901)
## Background `streamObject` was not working with the Anthropic provider. ## Summary Fix streaming with json output mode. ## Verification Ran example. ## Future Work * fine grained streaming beta header
1 parent 0d9583c commit a85c85f

File tree

5 files changed

+410
-366
lines changed

5 files changed

+410
-366
lines changed

.changeset/green-olives-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/anthropic': patch
3+
---
4+
5+
fix (provider/anthropic): streaming json output

examples/ai-core/src/stream-object/anthropic.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { z } from 'zod/v4';
55

66
async function main() {
77
const result = streamObject({
8-
model: anthropic('claude-3-5-sonnet-20240620'),
9-
maxOutputTokens: 2000,
8+
model: anthropic('claude-sonnet-4-20250514'),
9+
maxOutputTokens: 5000,
1010
schema: z.object({
1111
characters: z.array(
1212
z.object({
@@ -20,6 +20,10 @@ async function main() {
2020
}),
2121
prompt:
2222
'Generate 3 character descriptions for a fantasy role playing game.',
23+
onError: err => {
24+
console.error(err);
25+
},
26+
temperature: 0,
2327
});
2428

2529
for await (const partialObject of result.partialObjectStream) {

0 commit comments

Comments
 (0)