ai
Version:
AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript
80 lines (67 loc) • 2.49 kB
text/mdx
title: AnthropicStream
description: Learn to use AnthropicStream helper function in your application.
# `AnthropicStream`
<Note type="warning">AnthropicStream has been removed in AI SDK 4.0.</Note>
<Note type="warning">
AnthropicStream is part of the legacy Anthropic integration. It is not
compatible with the AI SDK 3.1 functions. It is recommended to use the [AI SDK
Anthropic Provider](/providers/ai-sdk-providers/anthropic) instead.
</Note>
It is a utility function that transforms the output from Anthropic's SDK into a ReadableStream. It uses AIStream under the hood, applying a specific parser for the Anthropic's response data structure.
## Import
### React
<Snippet text={`import { AnthropicStream } from "ai"`} prompt={false} />
## API Signature
### Parameters
<PropertiesTable
content={[
{
name: 'response',
type: 'Response',
description:
'The response object returned by a call made by the Provider SDK.',
},
{
name: 'callbacks',
type: 'AIStreamCallbacksAndOptions',
isOptional: true,
description:
'An object containing callback functions to handle the start, each token, and completion of the AI response. In the absence of this parameter, default behavior is implemented.',
properties: [
{
type: 'AIStreamCallbacksAndOptions',
parameters: [
{
name: 'onStart',
type: '() => Promise<void>',
description:
'An optional function that is called at the start of the stream processing.',
},
{
name: 'onCompletion',
type: '(completion: string) => Promise<void>',
description:
"An optional function that is called for every completion. It's passed the completion as a string.",
},
{
name: 'onFinal',
type: '(completion: string) => Promise<void>',
description:
'An optional function that is called once when the stream is closed with the final completion message.',
},
{
name: 'onToken',
type: '(token: string) => Promise<void>',
description:
"An optional function that is called for each token in the stream. It's passed the token as a string.",
},
],
},
],
},
]}
/>
### Returns
A `ReadableStream`.