
# `streamText()`

Streams text generations from a language model.

You can use the streamText function for interactive use cases such as chat bots and other real-time applications. You can also generate UI components with tools.

```ts
import { streamText } from 'ai';
__PROVIDER_IMPORT__;

const { textStream } = streamText({
  model: __MODEL__,
  prompt: 'Invent a new holiday and describe its traditions.',
});

for await (const textPart of textStream) {
  process.stdout.write(textPart);
}
```

For guidance on `runtimeContext`, `toolsContext`, tool `context`, and sensitive
context filtering, see [Runtime and Tool
Context](/docs/ai-sdk-core/runtime-and-tool-context).

To see `streamText` in action, check out [these examples](#examples).

## Import

<Snippet text={`import { streamText } from "ai"`} prompt={false} />

## API Signature

### Parameters

<PropertiesTable
  content={[
    {
      name: 'model',
      type: 'LanguageModel',
      description: "The language model to use. Example: openai('gpt-4.1')",
    },
    {
      name: 'instructions',
      type: 'Instructions',
      description:
        'Instructions to use that specify the behavior of the model.',
    },
    {
      name: 'prompt',
      type: 'string | Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>',
      description: 'The input prompt to generate the text from.',
    },
    {
      name: 'messages',
      type: 'Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>',
      description:
        'A list of messages that represent a conversation. Automatically converts UI messages from the useChat hook.',
      properties: [
        {
          type: 'SystemModelMessage',
          parameters: [
            {
              name: 'role',
              type: "'system'",
              description: 'The role for the system message.',
            },
            {
              name: 'content',
              type: 'string',
              description: 'The content of the message.',
            },
          ],
        },
        {
          type: 'UserModelMessage',
          parameters: [
            {
              name: 'role',
              type: "'user'",
              description: 'The role for the user message.',
            },
            {
              name: 'content',
              type: 'string | Array<TextPart | ImagePart | FilePart>',
              description: 'The content of the message.',
              properties: [
                {
                  type: 'TextPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'text'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'text',
                      type: 'string',
                      description: 'The text content of the message part.',
                    },
                  ],
                },
                {
                  type: 'ImagePart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'image'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'image',
                      type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
                      description:
                        'The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      isOptional: true,
                      description: 'The IANA media type of the image.',
                    },
                  ],
                },
                {
                  type: 'FilePart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'file'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'data',
                      type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
                      description:
                        'The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          type: 'AssistantModelMessage',
          parameters: [
            {
              name: 'role',
              type: "'assistant'",
              description: 'The role for the assistant message.',
            },
            {
              name: 'content',
              type: 'string | Array<TextPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart>',
              description: 'The content of the message.',
              properties: [
                {
                  type: 'TextPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'text'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'text',
                      type: 'string',
                      description: 'The text content of the message part.',
                    },
                  ],
                },
                {
                  type: 'ReasoningPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'reasoning'",
                      description: 'The type of the reasoning part.',
                    },
                    {
                      name: 'text',
                      type: 'string',
                      description: 'The reasoning text.',
                    },
                  ],
                },
                {
                  type: 'ReasoningFilePart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'reasoning-file'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'data',
                      type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
                      description:
                        'The file data. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                  ],
                },
                {
                  type: 'FilePart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'file'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'data',
                      type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
                      description:
                        'The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                    {
                      name: 'filename',
                      type: 'string',
                      description: 'The name of the file.',
                      isOptional: true,
                    },
                  ],
                },
                {
                  type: 'ToolCallPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'tool-call'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'toolCallId',
                      type: 'string',
                      description: 'The id of the tool call.',
                    },
                    {
                      name: 'toolName',
                      type: 'string',
                      description:
                        'The name of the tool, which typically would be the name of the function.',
                    },
                    {
                      name: 'input',
                      type: 'object based on zod schema',
                      description:
                        'Parameters generated by the model to be used by the tool.',
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          type: 'ToolModelMessage',
          parameters: [
            {
              name: 'role',
              type: "'tool'",
              description: 'The role for the assistant message.',
            },
            {
              name: 'content',
              type: 'Array<ToolResultPart>',
              description: 'The content of the message.',
              properties: [
                {
                  type: 'ToolResultPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'tool-result'",
                      description: 'The type of the message part.',
                    },
                    {
                      name: 'toolCallId',
                      type: 'string',
                      description:
                        'The id of the tool call the result corresponds to.',
                    },
                    {
                      name: 'toolName',
                      type: 'string',
                      description:
                        'The name of the tool the result corresponds to.',
                    },
                    {
                      name: 'result',
                      type: 'unknown',
                      description:
                        'The result returned by the tool after execution.',
                    },
                    {
                      name: 'isError',
                      type: 'boolean',
                      isOptional: true,
                      description:
                        'Whether the result is an error or an error message.',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'allowSystemInMessages',
      type: 'boolean',
      isOptional: true,
      description:
        'Whether system messages are allowed in the `prompt` or `messages` fields. Defaults to false. System messages in the `instructions` option are always allowed. Enabling this for user-controlled messages can create a prompt injection risk.',
    },
    {
      name: 'tools',
      type: 'ToolSet',
      description:
        'Tools that are accessible to and can be called by the model. The model needs to support calling tools.',
      properties: [
        {
          type: 'Tool',
          parameters: [
            {
              name: 'description',
              isOptional: true,
              type: 'string | ((options: { context: CONTEXT; experimental_sandbox?: Experimental_Sandbox }) => string)',
              description:
                'Information about the purpose of the tool including details on how and when it can be used by the model. Provide a string for a fixed description, or a function to derive the description from the tool-specific context and optional experimental sandbox before each model call.',
            },
            {
              name: 'inputSchema',
              type: 'Zod Schema | JSON Schema',
              description:
                'The schema of the input that the tool expects. The language model will use this to generate the input. It is also used to validate the output of the language model. Use descriptions to make the input understandable for the language model. You can either pass in a Zod schema or a JSON schema (using the `jsonSchema` function).',
            },
            {
              name: 'execute',
              isOptional: true,
              type: 'async (parameters: T, options: ToolExecutionOptions) => RESULT',
              description:
                'An async function that is called with the arguments from the tool call and produces a result. If not provided, the tool will not be executed automatically.',
              properties: [
                {
                  type: 'ToolExecutionOptions',
                  parameters: [
                    {
                      name: 'toolCallId',
                      type: 'string',
                      description:
                        'The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.',
                    },
                    {
                      name: 'messages',
                      type: 'ModelMessage[]',
                      description:
                        'Messages that were sent to the language model to initiate the response that contained the tool call. The messages do not include the system prompt nor the assistant response that contained the tool call.',
                    },
                    {
                      name: 'abortSignal',
                      type: 'AbortSignal',
                      description:
                        'An optional abort signal that indicates that the overall operation should be aborted.',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'toolChoice',
      isOptional: true,
      type: '"auto" | "none" | "required" | { "type": "tool", "toolName": string }',
      description:
        'The tool choice setting. It specifies how tools are selected for execution. The default is "auto". "none" disables tool execution. "required" requires tools to be executed. { "type": "tool", "toolName": string } specifies a specific tool to execute.',
    },
    {
      name: 'maxOutputTokens',
      type: 'number',
      isOptional: true,
      description: 'Maximum number of tokens to generate.',
    },
    {
      name: 'temperature',
      type: 'number',
      isOptional: true,
      description:
        'Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
    },
    {
      name: 'topP',
      type: 'number',
      isOptional: true,
      description:
        'Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
    },
    {
      name: 'topK',
      type: 'number',
      isOptional: true,
      description:
        'Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.',
    },
    {
      name: 'presencePenalty',
      type: 'number',
      isOptional: true,
      description:
        'Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.',
    },
    {
      name: 'frequencyPenalty',
      type: 'number',
      isOptional: true,
      description:
        'Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.',
    },
    {
      name: 'stopSequences',
      type: 'string[]',
      isOptional: true,
      description:
        'Sequences that will stop the generation of the text. If the model generates any of these sequences, it will stop generating further text.',
    },
    {
      name: 'seed',
      type: 'number',
      isOptional: true,
      description:
        'The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.',
    },
    {
      name: 'reasoning',
      type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'",
      isOptional: true,
      description:
        "Controls how much reasoning the model performs before generating a response. When omitted, the provider's default behavior is used. `'provider-default'` explicitly requests the provider's default. Providers that do not support reasoning will emit a warning. If reasoning-related `providerOptions` are also set, they take precedence and this parameter is ignored. See the [reasoning guide](/docs/ai-sdk-core/reasoning) for provider-specific mapping details.",
    },
    {
      name: 'maxRetries',
      type: 'number',
      isOptional: true,
      description:
        'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
    },
    {
      name: 'abortSignal',
      type: 'AbortSignal',
      isOptional: true,
      description:
        'An optional abort signal that can be used to cancel the call.',
    },
    {
      name: 'timeout',
      type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number; toolMs?: number; tools?: { [toolName]Ms?: number } }',
      isOptional: true,
      description:
        'Timeout in milliseconds. Can be specified as a number or as an object with totalMs, stepMs, chunkMs, toolMs, and/or tools properties. totalMs sets the total timeout for the entire call. stepMs sets the timeout for each individual step (LLM call). chunkMs sets the timeout between stream chunks - the call will abort if no new chunk is received within this duration. toolMs sets the default timeout for all tool executions. tools sets per-tool timeout overrides using the pattern {toolName}Ms (e.g. weatherMs, slowApiMs) that take precedence over toolMs - tool names are type-checked for autocomplete. If a tool takes longer than its timeout, it aborts and returns a tool-error so the model can respond or retry. Can be used alongside abortSignal.',
    },
    {
      name: 'headers',
      type: 'Record<string, string | undefined>',
      isOptional: true,
      description:
        'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
    },
    {
      name: 'telemetry',
      type: 'TelemetryOptions',
      isOptional: true,
      description: 'Telemetry configuration.',
      properties: [
        {
          type: 'TelemetryOptions',
          parameters: [
            {
              name: 'isEnabled',
              type: 'boolean',
              isOptional: true,
              description:
                'Enable or disable telemetry. Enabled by default. Set to `false` to opt out.',
            },
            {
              name: 'recordInputs',
              type: 'boolean',
              isOptional: true,
              description:
                'Enable or disable input recording. Enabled by default.',
            },
            {
              name: 'recordOutputs',
              type: 'boolean',
              isOptional: true,
              description:
                'Enable or disable output recording. Enabled by default.',
            },
            {
              name: 'functionId',
              type: 'string',
              isOptional: true,
              description:
                'Identifier for this function. Used to group telemetry data by function.',
            },
            {
              name: 'includeRuntimeContext',
              type: '{ [KEY in keyof CONTEXT]?: boolean }',
              isOptional: true,
              description:
                'Top-level runtime context properties that should be included in telemetry. Runtime context properties are excluded unless they are explicitly set to `true`. Lifecycle callbacks and returned results still receive the full `runtimeContext`.',
            },
            {
              name: 'includeToolsContext',
              type: '{ [TOOL_NAME in keyof InferToolSetContext<TOOLS>]?: { [KEY in keyof InferToolSetContext<TOOLS>[TOOL_NAME]]?: boolean } }',
              isOptional: true,
              description:
                'Top-level tool context properties that should be included in telemetry, configured per tool. Tool context properties are excluded unless they are explicitly set to `true`. Lifecycle callbacks and returned results still receive the full `toolsContext`.',
            },
            {
              name: 'integrations',
              isOptional: true,
              type: 'Telemetry | Telemetry[]',
              description:
                'Per-call telemetry integrations that receive lifecycle events. When provided, these replace any globally registered integrations for this call.',
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_transform',
      type: 'StreamTextTransform | Array<StreamTextTransform>',
      isOptional: true,
      description:
        'Optional stream transformations. They are applied in the order they are provided. The stream transformations must maintain the stream structure for streamText to work correctly.',
      properties: [
        {
          type: 'StreamTextTransform',
          parameters: [
            {
              name: 'transform',
              type: '(options: TransformOptions) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>',
              description: 'A transformation that is applied to the stream.',
              properties: [
                {
                  type: 'TransformOptions',
                  parameters: [
                    {
                      name: 'stopStream',
                      type: '() => void',
                      description: 'A function that stops the stream.',
                    },
                    {
                      name: 'tools',
                      type: 'TOOLS',
                      description: 'The tools that are available.',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'includeRawChunks',
      type: 'boolean',
      isOptional: true,
      description:
        'Deprecated. Use include.rawChunks instead. Whether to include raw chunks from the provider in the stream. When enabled, you will receive raw chunks with type "raw" that contain the unprocessed data from the provider. This allows access to cutting-edge provider features not yet wrapped by the AI SDK. Defaults to false.',
    },
    {
      name: 'providerOptions',
      type: 'Record<string,JSONObject> | undefined',
      isOptional: true,
      description:
        'Provider-specific options. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
    },
    {
      name: 'activeTools',
      type: 'ActiveTools<TOOLS>',
      isOptional: true,
      description:
        'Limits the tools that are available for the model to call without changing the tool call and result types in the result. All tools are active by default. Tool names are restricted to the string keys of the tool set.',
    },
    {
      name: 'toolApproval',
      type: 'ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT>',
      isOptional: true,
      description:
        "Approval configuration for this call. Pass a `GenericToolApprovalFunction` to handle all tool calls in one callback with `toolCall`, `tools`, `toolsContext`, `messages`, and `runtimeContext`, or pass a per-tool object where each key can be a status (`'not-applicable'`, `'approved'`, `'denied'`, or `'user-approval'`), an object form such as `{ type: 'denied', reason: 'blocked by policy' }`, or a `SingleToolApprovalFunction` that receives the tool input and options `toolCallId`, `messages`, `toolContext`, and `runtimeContext` (same shape as tool execution options without `abortSignal`, with `context` renamed to `toolContext`). The `RUNTIME_CONTEXT` type parameter matches the call's `runtimeContext`. A `GenericToolApprovalFunction` or `SingleToolApprovalFunction` may return `undefined` for the same effect as `'not-applicable'`. `'not-applicable'` is the default execution path and runs the tool without approval metadata. Use `'approved'`, `'denied'`, or their object forms when you want explicit automatic approval request/response parts in the output. Automatic approvals and denials can include a `reason`, which is forwarded to the emitted approval response. This setting takes precedence over a tool's `needsApproval` default.",
    },
    {
      name: 'experimental_refineToolInput',
      type: 'ToolInputRefinement<TOOLS>',
      isOptional: true,
      description:
        'Optional mapping of tool names to functions that refine parsed tool inputs. Each function receives the typed input for its tool and must return the same input type shape. The refined input is used for tool execution, stream parts, lifecycle callbacks, and telemetry.',
    },
    {
      name: 'stopWhen',
      type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>>',
      isOptional: true,
      description:
        'Condition for stopping the generation when there are tool results in the last step. When the condition is an array, any of the conditions can be met to stop the generation. Default: isStepCount(1).',
    },
    {
      name: 'prepareStep',
      type: '(options: PrepareStepOptions) => PrepareStepResult<TOOLS> | Promise<PrepareStepResult<TOOLS>>',
      isOptional: true,
      description:
        'Optional function that you can use to provide different settings for a step. You can modify the model, tool choices, active tools, instructions, input messages, and experimental sandbox for each step.',
      properties: [
        {
          type: 'PrepareStepFunction<TOOLS>',
          parameters: [
            {
              name: 'options',
              type: 'object',
              description: 'The options for the step.',
              properties: [
                {
                  type: 'PrepareStepOptions',
                  parameters: [
                    {
                      name: 'steps',
                      type: 'Array<StepResult<TOOLS>>',
                      description: 'The steps that have been executed so far.',
                    },
                    {
                      name: 'stepNumber',
                      type: 'number',
                      description:
                        'The number of the step that is being executed.',
                    },
                    {
                      name: 'model',
                      type: 'LanguageModel',
                      description: 'The model that is being used.',
                    },
                    {
                      name: 'instructions',
                      type: 'Instructions | undefined',
                      description:
                        'The instructions that will be sent to the model for the current step. If prepareStep returns an instructions override, those instructions carry forward to later steps.',
                    },
                    {
                      name: 'initialInstructions',
                      type: 'Instructions | undefined',
                      description:
                        'The initial instructions that were passed into generateText or streamText.',
                    },
                    {
                      name: 'messages',
                      type: 'Array<ModelMessage>',
                      description:
                        'The messages that will be sent to the model for the current step. If prepareStep returns a messages override, those messages carry forward to later steps.',
                    },
                    {
                      name: 'runtimeContext',
                      type: 'CONTEXT',
                      isOptional: true,
                      description:
                        'The shared runtime context passed via the `runtimeContext` setting.',
                    },
                    {
                      name: 'toolsContext',
                      type: 'InferToolSetContext<TOOLS>',
                      description:
                        'The per-tool context map passed via the `toolsContext` setting.',
                    },
                    {
                      name: 'experimental_sandbox',
                      type: 'Experimental_Sandbox | undefined',
                      isOptional: true,
                      description:
                        'The experimental sandbox environment passed via the `experimental_sandbox` setting.',
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          type: 'PrepareStepResult<TOOLS>',
          description:
            'Return value that can modify settings for the current step.',
          parameters: [
            {
              name: 'model',
              type: 'LanguageModel',
              isOptional: true,
              description:
                'Optionally override which LanguageModel instance is used for this step.',
            },
            {
              name: 'toolChoice',
              type: 'ToolChoice<TOOLS>',
              isOptional: true,
              description:
                'Optionally set which tool the model must call, or provide tool call configuration for this step.',
            },
            {
              name: 'activeTools',
              type: 'ActiveTools<TOOLS>',
              isOptional: true,
              description:
                'If provided, only these tools are enabled/available for this step.',
            },
            {
              name: 'instructions',
              type: 'Instructions',
              isOptional: true,
              description:
                'Optionally override the instructions sent to the model for this step. The override carries forward to later steps until prepareStep returns another instructions or system override.',
            },
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              isOptional: true,
              description:
                'Optionally override the full set of messages sent to the model for this step.',
            },
            {
              name: 'runtimeContext',
              type: 'CONTEXT',
              isOptional: true,
              description:
                'Shared runtime context. Changing it will affect this step and all subsequent steps.',
            },
            {
              name: 'toolsContext',
              type: 'InferToolSetContext<TOOLS>',
              description:
                'Per-tool context map. Changing it will affect tool-specific context in this step and all subsequent steps.',
            },
            {
              name: 'experimental_sandbox',
              type: 'Experimental_Sandbox',
              isOptional: true,
              description:
                'Experimental sandbox environment for this step. Changing it will affect tool execution in this step only.',
            },
            {
              name: 'providerOptions',
              type: 'ProviderOptions',
              isOptional: true,
              description:
                'Additional provider-specific options for this step. Can be used to pass provider-specific configuration such as container IDs for Anthropic code execution.',
            },
          ],
        },
      ],
    },
    {
      name: 'runtimeContext',
      type: 'CONTEXT',
      isOptional: true,
      description:
        'User-defined shared runtime context object passed to `prepareStep` and lifecycle callbacks.',
    },
    {
      name: 'toolsContext',
      type: 'InferToolSetContext<TOOLS>',
      description:
        'Per-tool context map keyed by tool name. Required when at least one tool defines `contextSchema`; not accepted when no tools need context.',
    },
    {
      name: 'experimental_sandbox',
      type: 'Experimental_Sandbox',
      isOptional: true,
      description:
        'Experimental sandbox environment that is passed through to `prepareStep`, tool description functions, and tool execution. Tools can access it from their description function options and execution options.',
    },
    {
      name: 'experimental_download',
      type: '(requestedDownloads: Array<{ url: URL; isUrlSupportedByModel: boolean }>) => Promise<Array<null | { data: Uint8Array; mediaType?: string }>>',
      isOptional: true,
      description:
        'Custom download function to control how URLs are fetched when they appear in prompts. By default, files are downloaded if the model does not support the URL for the given media type. Experimental feature. Return null to pass the URL directly to the model (when supported), or return downloaded content with data and media type.',
    },
    {
      name: 'include',
      type: '{ requestBody?: boolean; requestMessages?: boolean; rawChunks?: boolean }',
      isOptional: true,
      description:
        'Controls inclusion of request body and request messages in step results, and raw provider chunks in the stream. By default, request body, request messages, and raw chunks are excluded to reduce memory usage. Set requestBody or requestMessages to true when you need access to the data. Set rawChunks to true when you need access to raw provider chunks.',
      properties: [
        {
          type: 'Object',
          parameters: [
            {
              name: 'requestBody',
              type: 'boolean',
              isOptional: true,
              description:
                'Whether to include the request body in step results. The request body can be large when sending images or files. Default: false.',
            },
            {
              name: 'requestMessages',
              type: 'boolean',
              isOptional: true,
              description:
                'Whether to include the request messages in step results. The request messages can be large when sending images or files. Default: false.',
            },
            {
              name: 'rawChunks',
              type: 'boolean',
              isOptional: true,
              description:
                'Whether to include raw chunks from the provider in the stream. When enabled, raw chunks with type "raw" contain unprocessed provider data. Default: false.',
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_repairToolCall',
      type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>',
      isOptional: true,
      description:
        'A function that attempts to repair a tool call that failed to parse. Return either a repaired tool call or null if the tool call cannot be repaired.',
      properties: [
        {
          type: 'ToolCallRepairOptions',
          parameters: [
            {
              name: 'instructions',
              type: 'Instructions | undefined',
              description: 'The instructions provided to the model.',
            },
            {
              name: 'system',
              type: 'Instructions | undefined',
              isOptional: true,
              description:
                'The instructions provided to the model. Deprecated: use `instructions` instead.',
            },
            {
              name: 'messages',
              type: 'ModelMessage[]',
              description: 'The messages in the current generation step.',
            },
            {
              name: 'toolCall',
              type: 'LanguageModelV4ToolCall',
              description: 'The tool call that failed to parse.',
            },
            {
              name: 'tools',
              type: 'TOOLS',
              description: 'The tools that are available.',
            },
            {
              name: 'inputSchema',
              type: '(options: { toolName: string }) => JSONSchema7',
              description:
                'A function that returns the JSON Schema for a tool.',
            },
            {
              name: 'error',
              type: 'NoSuchToolError | InvalidToolInputError',
              description:
                'The error that occurred while parsing the tool call.',
            },
          ],
        },
      ],
    },
    {
      name: 'onChunk',
      type: '(event: OnChunkResult) => Promise<void> |void',
      isOptional: true,
      description:
        'Callback that is called for each stream part. The stream processing will pause until the callback promise is resolved.',
      properties: [
        {
          type: 'OnChunkResult',
          parameters: [
            {
              name: 'chunk',
              type: 'TextStreamPart<TOOLS>',
              description:
                'The stream part. This is the same union as `stream` and includes `start`, `start-step`, `text-start`, `text-delta`, `text-end`, `reasoning-start`, `reasoning-delta`, `reasoning-end`, `custom`, `source`, `file`, `reasoning-file`, `tool-call`, `tool-input-start`, `tool-input-delta`, `tool-input-end`, `tool-result`, `tool-error`, `tool-output-denied`, `tool-approval-request`, `tool-approval-response`, `finish-step`, `finish`, `abort`, `error`, and `raw`.',
              properties: [
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'text-delta'",
                      description:
                        'The type to identify the object as text delta.',
                    },
                    {
                      name: 'text',
                      type: 'string',
                      description: 'The text delta.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'reasoning-delta'",
                      description:
                        'The type to identify the object as reasoning delta.',
                    },
                    {
                      name: 'text',
                      type: 'string',
                      description: 'The reasoning text delta.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'source'",
                      description: 'The type to identify the object as source.',
                    },
                    {
                      name: 'source',
                      type: 'Source',
                      description: 'The source.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'custom'",
                      description:
                        'The type to identify the object as custom content.',
                    },
                    {
                      name: 'kind',
                      type: 'string',
                      description:
                        'The kind of custom content, in the format {provider}.{provider-type} (e.g. openai.compaction).',
                    },
                    {
                      name: 'providerMetadata',
                      type: 'ProviderMetadata',
                      isOptional: true,
                      description:
                        'Optional provider metadata for the custom content.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'tool-call'",
                      description:
                        'The type to identify the object as tool call.',
                    },
                    {
                      name: 'toolCallId',
                      type: 'string',
                      description: 'The id of the tool call.',
                    },
                    {
                      name: 'toolName',
                      type: 'string',
                      description:
                        'The name of the tool, which typically would be the name of the function.',
                    },
                    {
                      name: 'input',
                      type: 'object based on zod schema',
                      description:
                        'Parameters generated by the model to be used by the tool.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'tool-input-start'",
                      description:
                        'Indicates the start of streamed tool input.',
                    },
                    {
                      name: 'id',
                      type: 'string',
                      description: 'The id of the tool call.',
                    },
                    {
                      name: 'toolName',
                      type: 'string',
                      description:
                        'The name of the tool, which typically would be the name of the function.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  parameters: [
                    {
                      name: 'type',
                      type: "'tool-input-delta'",
                      description:
                        'The type to identify the object as streamed tool input delta.',
                    },
                    {
                      name: 'id',
                      type: 'string',
                      description: 'The id of the tool call.',
                    },
                    {
                      name: 'toolName',
                      type: 'string',
                      description:
                        'The name of the tool, which typically would be the name of the function.',
                    },
                    {
                      name: 'delta',
                      type: 'string',
                      description: 'The text delta of the tool input.',
                    },
                  ],
                },
                {
                  type: 'TextStreamPart',
                  description: 'The result of a tool call execution.',
                  parameters: [
                    {
                      name: 'type',
                      type: "'tool-result'",
                      description:
                        'The type to identify the object as tool result.',
                    },
                    {
                      name: 'toolCallId',
                      type: 'string',
                      description: 'The id of the tool call.',
                    },
                    {
                      name: 'toolName',
                      type: 'string',
                      description:
                        'The name of the tool, which typically would be the name of the function.',
                    },
                    {
                      name: 'input',
                      type: 'object based on zod schema',
                      description:
                        'Parameters generated by the model to be used by the tool.',
                    },
                    {
                      name: 'output',
                      type: 'any',
                      description:
                        'The result returned by the tool after execution has completed.',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'onError',
      type: '(event: OnErrorResult) => Promise<void> |void',
      isOptional: true,
      description:
        'Callback that is called when an error occurs during streaming. You can use it to log errors.',
      properties: [
        {
          type: 'OnErrorResult',
          parameters: [
            {
              name: 'error',
              type: 'unknown',
              description: 'The error that occurred.',
            },
          ],
        },
      ],
    },
    {
      name: 'output',
      type: 'Output',
      isOptional: true,
      description:
        'Specification for parsing structured outputs from the LLM response.',
      properties: [
        {
          type: 'Output',
          parameters: [
            {
              name: 'Output.text()',
              type: 'Output',
              description:
                'Output specification for text generation (default).',
            },
            {
              name: 'Output.object()',
              type: 'Output',
              description:
                'Output specification for typed object generation using schemas. When the model generates a text response, it will return an object that matches the schema.',
              properties: [
                {
                  type: 'Options',
                  parameters: [
                    {
                      name: 'schema',
                      type: 'Schema<OBJECT>',
                      description: 'The schema of the object to generate.',
                    },
                    {
                      name: 'name',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional name of the output. Used by some providers for additional LLM guidance.',
                    },
                    {
                      name: 'description',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional description of the output. Used by some providers for additional LLM guidance.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'Output.array()',
              type: 'Output',
              description:
                'Output specification for array generation. When the model generates a text response, it will return an array of elements.',
              properties: [
                {
                  type: 'Options',
                  parameters: [
                    {
                      name: 'element',
                      type: 'Schema<ELEMENT>',
                      description:
                        'The schema of the array elements to generate.',
                    },
                    {
                      name: 'name',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional name of the output. Used by some providers for additional LLM guidance.',
                    },
                    {
                      name: 'description',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional description of the output. Used by some providers for additional LLM guidance.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'Output.choice()',
              type: 'Output',
              description:
                'Output specification for choice generation. When the model generates a text response, it will return a one of the choice options.',
              properties: [
                {
                  type: 'Options',
                  parameters: [
                    {
                      name: 'options',
                      type: 'Array<string>',
                      description: 'The available choices.',
                    },
                    {
                      name: 'name',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional name of the output. Used by some providers for additional LLM guidance.',
                    },
                    {
                      name: 'description',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional description of the output. Used by some providers for additional LLM guidance.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'Output.json()',
              type: 'Output',
              description:
                'Output specification for unstructured JSON generation. When the model generates a text response, it will return a JSON object.',
              properties: [
                {
                  type: 'Options',
                  parameters: [
                    {
                      name: 'name',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional name of the output. Used by some providers for additional LLM guidance.',
                    },
                    {
                      name: 'description',
                      type: 'string',
                      isOptional: true,
                      description:
                        'Optional description of the output. Used by some providers for additional LLM guidance.',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'onStepFinish',
      type: '(result: onStepFinishResult) => Promise<void> | void',
      isOptional: true,
      description: 'Callback that is called when a step is finished.',
      properties: [
        {
          type: 'onStepFinishResult',
          parameters: [
            {
              name: 'stepType',
              type: '"initial" | "continue" | "tool-result"',
              description:
                'The type of step. The first step is always an "initial" step, and subsequent steps are either "continue" steps or "tool-result" steps.',
            },
            {
              name: 'finishReason',
              type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"',
              description:
                'The unified finish reason why the generation finished.',
            },
            {
              name: 'rawFinishReason',
              type: 'string | undefined',
              description:
                'The raw reason why the generation finished (from the provider).',
            },
            {
              name: 'usage',
              type: 'LanguageModelUsage',
              description: 'The token usage of the step.',
              properties: [
                {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description:
                        'The total number of input (prompt) tokens used.',
                    },
                    {
                      name: 'inputTokenDetails',
                      type: 'LanguageModelInputTokenDetails',
                      description:
                        'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
                      properties: [
                        {
                          type: 'LanguageModelInputTokenDetails',
                          parameters: [
                            {
                              name: 'noCacheTokens',
                              type: 'number | undefined',
                              description:
                                'The number of non-cached input (prompt) tokens used.',
                            },
                            {
                              name: 'cacheReadTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens read.',
                            },
                            {
                              name: 'cacheWriteTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens written.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description:
                        'The number of total output (completion) tokens used.',
                    },
                    {
                      name: 'outputTokenDetails',
                      type: 'LanguageModelOutputTokenDetails',
                      description:
                        'Detailed information about the output (completion) tokens.',
                      properties: [
                        {
                          type: 'LanguageModelOutputTokenDetails',
                          parameters: [
                            {
                              name: 'textTokens',
                              type: 'number | undefined',
                              description: 'The number of text tokens used.',
                            },
                            {
                              name: 'reasoningTokens',
                              type: 'number | undefined',
                              description:
                                'The number of reasoning tokens used.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description: 'The total number of tokens used.',
                    },
                    {
                      name: 'raw',
                      type: 'object | undefined',
                      isOptional: true,
                      description:
                        "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
                    },
                  ],
                },
              ],
            },
            {
              name: 'performance',
              type: 'StepResultPerformance',
              description: 'Timing and throughput metrics for the step.',
              properties: [
                {
                  type: 'StepResultPerformance',
                  parameters: [
                    {
                      name: 'effectiveOutputTokensPerSecond',
                      type: 'number',
                      description:
                        'Effective number of output tokens per second over the full language model response.',
                    },
                    {
                      name: 'outputTokensPerSecond',
                      type: 'number | undefined',
                      description:
                        'Number of output tokens per second after the first generated output chunk was received. Only available for streaming steps.',
                    },
                    {
                      name: 'inputTokensPerSecond',
                      type: 'number | undefined',
                      description:
                        'Number of input tokens processed per second before the first generated output chunk was received. Only available for streaming steps.',
                    },
                    {
                      name: 'effectiveTotalTokensPerSecond',
                      type: 'number',
                      description:
                        'Effective number of input and output tokens per second over the full language model response.',
                    },
                    {
                      name: 'stepTimeMs',
                      type: 'number',
                      description:
                        'Total time spent on the step, including language model response time and tool execution time, in milliseconds.',
                    },
                    {
                      name: 'responseTimeMs',
                      type: 'number',
                      description:
                        'Time spent waiting for the language model response in milliseconds.',
                    },
                    {
                      name: 'toolExecutionMs',
                      type: 'Readonly<Record<string, number>>',
                      description:
                        'Time spent executing each client-side tool call in the step in milliseconds, keyed by tool call ID.',
                    },
                    {
                      name: 'timeToFirstOutputMs',
                      type: 'number | undefined',
                      description:
                        'Time until the first generated output chunk was received in milliseconds. Only available for streaming steps.',
                    },
                    {
                      name: 'timeBetweenOutputChunksMs',
                      type: 'OutputChunkTimingStats | undefined',
                      description:
                        'Timing statistics for the gaps between generated output chunks in milliseconds. Only available for streaming steps with at least two output chunks.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'text',
              type: 'string',
              description: 'The full text that has been generated.',
            },
            {
              name: 'reasoningText',
              type: 'string | undefined',
              description:
                'The reasoning text of the model (only available for some models).',
            },
            {
              name: 'sources',
              type: 'Array<Source>',
              description: 'Sources that have been used in the final step.',
              properties: [
                {
                  type: 'Source',
                  parameters: [
                    {
                      name: 'sourceType',
                      type: "'url'",
                      description:
                        'A URL source. This is return by web search RAG models.',
                    },
                    {
                      name: 'id',
                      type: 'string',
                      description: 'The ID of the source.',
                    },
                    {
                      name: 'url',
                      type: 'string',
                      description: 'The URL of the source.',
                    },
                    {
                      name: 'title',
                      type: 'string',
                      isOptional: true,
                      description: 'The title of the source.',
                    },
                    {
                      name: 'providerMetadata',
                      type: 'SharedV2ProviderMetadata',
                      isOptional: true,
                      description:
                        'Additional provider metadata for the source.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'files',
              type: 'Array<GeneratedFile>',
              description: 'All files that were generated in this step.',
              properties: [
                {
                  type: 'GeneratedFile',
                  parameters: [
                    {
                      name: 'base64',
                      type: 'string',
                      description: 'File as a base64 encoded string.',
                    },
                    {
                      name: 'uint8Array',
                      type: 'Uint8Array',
                      description: 'File as a Uint8Array.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'toolCalls',
              type: 'ToolCall[]',
              description: 'The tool calls that have been executed.',
            },
            {
              name: 'toolResults',
              type: 'ToolResult[]',
              description: 'The tool results that have been generated.',
            },
            {
              name: 'warnings',
              type: 'Warning[] | undefined',
              description:
                'Warnings from the model provider (e.g. unsupported settings).',
            },
            {
              name: 'response',
              type: 'Response',
              isOptional: true,
              description: 'Response metadata.',
              properties: [
                {
                  type: 'Response',
                  parameters: [
                    {
                      name: 'id',
                      type: 'string',
                      description:
                        'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
                    },
                    {
                      name: 'modelId',
                      type: 'string',
                      description:
                        'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
                    },
                    {
                      name: 'timestamp',
                      type: 'Date',
                      description:
                        'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
                    },
                    {
                      name: 'headers',
                      isOptional: true,
                      type: 'Record<string, string>',
                      description: 'Optional response headers.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'isContinued',
              type: 'boolean',
              description:
                'True when there will be a continuation step with a continuation text.',
            },
            {
              name: 'providerMetadata',
              type: 'Record<string,JSONObject> | undefined',
              isOptional: true,
              description:
                'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
            },
          ],
        },
      ],
    },
    {
      name: 'onEnd',
      type: '(result: OnEndResult) => Promise<void> | void',
      isOptional: true,
      description:
        'Callback that is called when the LLM response and all request tool executions (for tools that have an `execute` function) are finished.',
      properties: [
        {
          type: 'OnEndResult',
          parameters: [
            {
              name: 'finishReason',
              type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"',
              description:
                'The unified finish reason why the generation finished.',
            },
            {
              name: 'rawFinishReason',
              type: 'string | undefined',
              description:
                'The raw reason why the generation finished (from the provider).',
            },
            {
              name: 'usage',
              type: 'LanguageModelUsage',
              description: 'The token usage of last step.',
              properties: [
                {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description:
                        'The total number of input (prompt) tokens used.',
                    },
                    {
                      name: 'inputTokenDetails',
                      type: 'LanguageModelInputTokenDetails',
                      description:
                        'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
                      properties: [
                        {
                          type: 'LanguageModelInputTokenDetails',
                          parameters: [
                            {
                              name: 'noCacheTokens',
                              type: 'number | undefined',
                              description:
                                'The number of non-cached input (prompt) tokens used.',
                            },
                            {
                              name: 'cacheReadTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens read.',
                            },
                            {
                              name: 'cacheWriteTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens written.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description:
                        'The number of total output (completion) tokens used.',
                    },
                    {
                      name: 'outputTokenDetails',
                      type: 'LanguageModelOutputTokenDetails',
                      description:
                        'Detailed information about the output (completion) tokens.',
                      properties: [
                        {
                          type: 'LanguageModelOutputTokenDetails',
                          parameters: [
                            {
                              name: 'textTokens',
                              type: 'number | undefined',
                              description: 'The number of text tokens used.',
                            },
                            {
                              name: 'reasoningTokens',
                              type: 'number | undefined',
                              description:
                                'The number of reasoning tokens used.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description: 'The total number of tokens used.',
                    },
                    {
                      name: 'raw',
                      type: 'object | undefined',
                      isOptional: true,
                      description:
                        "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
                    },
                  ],
                },
              ],
            },
            {
              name: 'totalUsage',
              type: 'LanguageModelUsage',
              description: 'The total token usage from all steps.',
              properties: [
                {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description: 'The number of input (prompt) tokens used.',
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description:
                        'The number of output (completion) tokens used.',
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description:
                        'The total number of tokens as reported by the provider. This number might be different from the sum of inputTokens and outputTokens and e.g. include reasoning tokens or other overhead.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'providerMetadata',
              type: 'Record<string,JSONObject> | undefined',
              description:
                'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
            },
            {
              name: 'text',
              type: 'string',
              description: 'The full text that has been generated.',
            },
            {
              name: 'reasoning',
              type: 'string | undefined',
              description:
                'The reasoning text of the model (only available for some models).',
            },
            {
              name: 'reasoning',
              type: 'Array<ReasoningDetail>',
              description:
                'The reasoning details of the model (only available for some models).',
              properties: [
                {
                  type: 'ReasoningDetail',
                  parameters: [
                    {
                      name: 'type',
                      type: "'text'",
                      description: 'The type of the reasoning detail.',
                    },
                    {
                      name: 'text',
                      type: 'string',
                      description: 'The text content (only for type "text").',
                    },
                    {
                      name: 'signature',
                      type: 'string',
                      isOptional: true,
                      description: 'Optional signature (only for type "text").',
                    },
                  ],
                },
                {
                  type: 'ReasoningDetail',
                  parameters: [
                    {
                      name: 'type',
                      type: "'redacted'",
                      description: 'The type of the reasoning detail.',
                    },
                    {
                      name: 'data',
                      type: 'string',
                      description:
                        'The redacted data content (only for type "redacted").',
                    },
                  ],
                },
              ],
            },
            {
              name: 'sources',
              type: 'Array<Source>',
              description: 'Sources that have been used in the final step.',
              properties: [
                {
                  type: 'Source',
                  parameters: [
                    {
                      name: 'sourceType',
                      type: "'url'",
                      description:
                        'A URL source. This is return by web search RAG models.',
                    },
                    {
                      name: 'id',
                      type: 'string',
                      description: 'The ID of the source.',
                    },
                    {
                      name: 'url',
                      type: 'string',
                      description: 'The URL of the source.',
                    },
                    {
                      name: 'title',
                      type: 'string',
                      isOptional: true,
                      description: 'The title of the source.',
                    },
                    {
                      name: 'providerMetadata',
                      type: 'SharedV2ProviderMetadata',
                      isOptional: true,
                      description:
                        'Additional provider metadata for the source.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'files',
              type: 'Array<GeneratedFile>',
              description: 'Files that were generated in all steps.',
              properties: [
                {
                  type: 'GeneratedFile',
                  parameters: [
                    {
                      name: 'base64',
                      type: 'string',
                      description: 'File as a base64 encoded string.',
                    },
                    {
                      name: 'uint8Array',
                      type: 'Uint8Array',
                      description: 'File as a Uint8Array.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'toolCalls',
              type: 'ToolCall[]',
              description: 'The tool calls that have been executed.',
            },
            {
              name: 'toolResults',
              type: 'ToolResult[]',
              description: 'The tool results that have been generated.',
            },
            {
              name: 'warnings',
              type: 'Warning[] | undefined',
              description:
                'Warnings from the model provider (e.g. unsupported settings).',
            },
            {
              name: 'response',
              type: 'Response',
              isOptional: true,
              description: 'Response metadata.',
              properties: [
                {
                  type: 'Response',
                  parameters: [
                    {
                      name: 'id',
                      type: 'string',
                      description:
                        'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
                    },
                    {
                      name: 'modelId',
                      type: 'string',
                      description:
                        'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
                    },
                    {
                      name: 'timestamp',
                      type: 'Date',
                      description:
                        'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
                    },
                    {
                      name: 'headers',
                      isOptional: true,
                      type: 'Record<string, string>',
                      description: 'Optional response headers.',
                    },
                    {
                      name: 'messages',
                      type: 'Array<ResponseMessage>',
                      description:
                        'The response messages generated during this step. It consists of an assistant message, potentially containing tool calls. When there are tool results in this step, there is an additional tool message with the available tool results. If there are tools that do not have execute functions, they are not included in the tool results and need to be added separately.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'steps',
              type: 'Array<StepResult>',
              description:
                'Response information for every step. You can use this to get information about intermediate steps, such as the tool calls or the response headers.',
            },
            {
              name: 'finalStep',
              type: 'StepResult',
              description:
                'The final step. This is a shortcut for `steps.at(-1)`.',
            },
            {
              name: 'runtimeContext',
              type: 'CONTEXT',
              description:
                'The final state of the user-defined runtime context object when the stream is aborted.',
            },
          ],
        },
      ],
    },
    {
      name: 'onFinish',
      type: '(result: OnEndResult) => Promise<void> | void',
      isOptional: true,
      description: 'Deprecated alias for `onEnd`.',
    },
    {
      name: 'onAbort',
      type: '(event: OnAbortResult) => Promise<void> | void',
      isOptional: true,
      description:
        'Callback that is called when a stream is aborted via AbortSignal. You can use it to perform cleanup operations.',
      properties: [
        {
          type: 'OnAbortResult',
          parameters: [
            {
              name: 'steps',
              type: 'Array<StepResult>',
              description: 'Details for all previously finished steps.',
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_onStart',
      type: '(event: GenerateTextStartEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        'Callback that is called when the streamText operation begins, before any LLM calls are made. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
      properties: [
        {
          type: 'GenerateTextStartEvent',
          parameters: [
            {
              name: 'provider',
              type: 'string',
              description:
                'The provider identifier (e.g., "openai", "anthropic").',
            },
            {
              name: 'modelId',
              type: 'string',
              description: 'The specific model identifier (e.g., "gpt-4o").',
            },
            {
              name: 'instructions',
              type: 'Instructions | undefined',
              description: 'The instructions provided to the model.',
            },
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              description: 'The messages for this generation.',
            },
            {
              name: 'tools',
              type: 'TOOLS | undefined',
              description: 'The tools available for this generation.',
            },
            {
              name: 'toolChoice',
              type: 'ToolChoice<TOOLS> | undefined',
              description: 'The tool choice strategy for this generation.',
            },
            {
              name: 'activeTools',
              type: 'ActiveTools<TOOLS>',
              description:
                'Limits which tools are available for the model to call.',
            },
            {
              name: 'maxOutputTokens',
              type: 'number | undefined',
              description: 'Maximum number of tokens to generate.',
            },
            {
              name: 'temperature',
              type: 'number | undefined',
              description: 'Sampling temperature for generation.',
            },
            {
              name: 'topP',
              type: 'number | undefined',
              description: 'Top-p (nucleus) sampling parameter.',
            },
            {
              name: 'topK',
              type: 'number | undefined',
              description: 'Top-k sampling parameter.',
            },
            {
              name: 'presencePenalty',
              type: 'number | undefined',
              description: 'Presence penalty for generation.',
            },
            {
              name: 'frequencyPenalty',
              type: 'number | undefined',
              description: 'Frequency penalty for generation.',
            },
            {
              name: 'stopSequences',
              type: 'string[] | undefined',
              description: 'Sequences that will stop generation.',
            },
            {
              name: 'seed',
              type: 'number | undefined',
              description: 'Random seed for reproducible generation.',
            },
            {
              name: 'maxRetries',
              type: 'number',
              description: 'Maximum number of retries for failed requests.',
            },
            {
              name: 'timeout',
              type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
              description:
                'Timeout configuration for the generation. Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.',
            },
            {
              name: 'headers',
              type: 'Record<string, string | undefined> | undefined',
              description: 'Additional HTTP headers sent with the request.',
            },
            {
              name: 'providerOptions',
              type: 'ProviderOptions | undefined',
              description: 'Additional provider-specific options.',
            },
            {
              name: 'output',
              type: 'OUTPUT | undefined',
              description:
                'The output specification for structured outputs, if configured.',
            },
            {
              name: 'abortSignal',
              type: 'AbortSignal | undefined',
              description: 'Abort signal for cancelling the operation.',
            },
            {
              name: 'include',
              type: '{ requestBody?: boolean; requestMessages?: boolean } | undefined',
              description:
                'Settings for controlling what data is included in step results.',
            },
            {
              name: 'runtimeContext',
              type: 'CONTEXT',
              description:
                'User-defined shared runtime context object that flows through the entire generation lifecycle.',
            },
            {
              name: 'toolsContext',
              type: 'InferToolSetContext<TOOLS>',
              description:
                'Per-tool context map passed via `toolsContext`, keyed by tool name.',
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_onStepStart',
      type: '(event: GenerateTextStepStartEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        'Callback that is called when a step (LLM call) begins, before the provider is called. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
      properties: [
        {
          type: 'GenerateTextStepStartEvent',
          parameters: [
            {
              name: 'stepNumber',
              type: 'number',
              description: 'Zero-based index of the current step.',
            },
            {
              name: 'provider',
              type: 'string',
              description:
                'The provider identifier (e.g., "openai", "anthropic").',
            },
            {
              name: 'modelId',
              type: 'string',
              description: 'The specific model identifier (e.g., "gpt-4o").',
            },
            {
              name: 'instructions',
              type: 'Instructions | undefined',
              description:
                'The instructions provided to the model for this step.',
            },
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              description:
                'The messages that will be sent to the model for this step. Uses the user-facing ModelMessage format. May be overridden by prepareStep. If prepareStep returns a messages override, those messages carry forward to later steps.',
            },
            {
              name: 'tools',
              type: 'TOOLS | undefined',
              description: 'The tools available for this generation.',
            },
            {
              name: 'toolChoice',
              type: 'LanguageModelV4ToolChoice | undefined',
              description: 'The tool choice configuration for this step.',
            },
            {
              name: 'activeTools',
              type: 'ActiveTools<TOOLS>',
              description: 'Limits which tools are available for this step.',
            },
            {
              name: 'steps',
              type: 'ReadonlyArray<StepResult<TOOLS>>',
              description:
                'Array of results from previous steps (empty for the first step).',
            },
            {
              name: 'providerOptions',
              type: 'ProviderOptions | undefined',
              description:
                'Additional provider-specific options for this step.',
            },
            {
              name: 'timeout',
              type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
              description: 'Timeout configuration for the generation.',
            },
            {
              name: 'headers',
              type: 'Record<string, string | undefined> | undefined',
              description: 'Additional HTTP headers sent with the request.',
            },
            {
              name: 'stopWhen',
              type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
              description: 'Condition(s) for stopping the generation.',
            },
            {
              name: 'output',
              type: 'OUTPUT | undefined',
              description:
                'The output specification for structured outputs, if configured.',
            },
            {
              name: 'abortSignal',
              type: 'AbortSignal | undefined',
              description: 'Abort signal for cancelling the operation.',
            },
            {
              name: 'include',
              type: '{ requestBody?: boolean; requestMessages?: boolean } | undefined',
              description:
                'Settings for controlling what data is included in step results.',
            },
            {
              name: 'runtimeContext',
              type: 'CONTEXT',
              description:
                'User-defined shared runtime context object. May be updated from prepareStep between steps.',
            },
            {
              name: 'toolsContext',
              type: 'InferToolSetContext<TOOLS>',
              description:
                'Per-tool context map. May be updated from prepareStep between steps.',
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_onLanguageModelCallStart',
      type: '(event: LanguageModelCallStartEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        'Callback that is called immediately before the provider model call begins. Unlike `experimental_onStepStart`, this callback is scoped to model work only and excludes any later client-side tool execution. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
      properties: [
        {
          type: 'LanguageModelCallStartEvent',
          parameters: [
            {
              name: 'callId',
              type: 'string',
              description: 'Unique identifier for the generation call.',
            },
            {
              name: 'provider',
              type: 'string',
              description: 'The provider identifier for this model call.',
            },
            {
              name: 'modelId',
              type: 'string',
              description: 'The specific model identifier for this model call.',
            },
            {
              name: 'instructions',
              type: 'Instructions | undefined',
              description: 'The instructions that will be sent to the model.',
            },
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              description: 'The messages that will be sent to the model.',
            },
            {
              name: 'tools',
              type: 'ReadonlyArray<Record<string, unknown>> | undefined',
              description:
                'Prepared tool definitions for the model call, if any.',
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_onLanguageModelCallEnd',
      type: '(event: LanguageModelCallEndEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        'Callback that is called after the model response has been normalized and parsed, but before any client-side tool execution begins. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
      properties: [
        {
          type: 'LanguageModelCallEndEvent',
          parameters: [
            {
              name: 'callId',
              type: 'string',
              description: 'Unique identifier for the generation call.',
            },
            {
              name: 'provider',
              type: 'string',
              description: 'The provider identifier for this model call.',
            },
            {
              name: 'modelId',
              type: 'string',
              description: 'The specific model identifier for this model call.',
            },
            {
              name: 'finishReason',
              type: 'FinishReason',
              description: 'The unified reason why the model call finished.',
            },
            {
              name: 'usage',
              type: 'LanguageModelUsage',
              description: 'Token usage reported by the model call.',
            },
            {
              name: 'content',
              type: 'ReadonlyArray<ContentPart<TOOLS>>',
              description:
                'The content parts produced by the model call (text, reasoning, files, tool calls, etc.).',
            },
            {
              name: 'responseId',
              type: 'string',
              description:
                'The provider-returned response ID for this model call.',
            },
            {
              name: 'performance',
              type: '{ responseTimeMs: number; effectiveOutputTokensPerSecond: number; outputTokensPerSecond: number | undefined; inputTokensPerSecond: number | undefined; effectiveTotalTokensPerSecond: number; timeToFirstOutputMs: number | undefined; timeBetweenOutputChunksMs?: OutputChunkTimingStats }',
              description: 'Performance metrics for the model call.',
              properties: [
                {
                  type: 'LanguageModelCallPerformance',
                  parameters: [
                    {
                      name: 'responseTimeMs',
                      type: 'number',
                      description:
                        'Time spent waiting for the language model response in milliseconds.',
                    },
                    {
                      name: 'effectiveOutputTokensPerSecond',
                      type: 'number',
                      description:
                        'Effective number of output tokens per second over the full language model response.',
                    },
                    {
                      name: 'outputTokensPerSecond',
                      type: 'number | undefined',
                      description:
                        'Number of output tokens per second after the first generated output chunk was received. Only available for streaming model calls.',
                    },
                    {
                      name: 'inputTokensPerSecond',
                      type: 'number | undefined',
                      description:
                        'Number of input tokens processed per second before the first generated output chunk was received. Only available for streaming model calls.',
                    },
                    {
                      name: 'effectiveTotalTokensPerSecond',
                      type: 'number',
                      description:
                        'Effective number of input and output tokens per second over the full language model response.',
                    },
                    {
                      name: 'timeToFirstOutputMs',
                      type: 'number | undefined',
                      description:
                        'Time until the first generated output chunk was received in milliseconds. Only available for streaming model calls.',
                    },
                    {
                      name: 'timeBetweenOutputChunksMs',
                      type: 'OutputChunkTimingStats | undefined',
                      description:
                        'Timing statistics for the gaps between generated output chunks in milliseconds. Only available for streaming model calls with at least two output chunks.',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'onToolExecutionStart',
      type: '(event: ToolExecutionStartEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        "Callback that is called right before a tool's execute function runs. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).",
      properties: [
        {
          type: 'ToolExecutionStartEvent',
          parameters: [
            {
              name: 'callId',
              type: 'string',
              description:
                'Unique identifier for this generation call, used to correlate events.',
            },
            {
              name: 'toolCall',
              type: 'TypedToolCall<TOOLS>',
              description:
                'The full tool call object containing toolName, toolCallId, input, and metadata.',
            },
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              description:
                'Messages that were sent to the language model to initiate the response that contained the tool call. Does not include the system prompt nor the assistant response that contained the tool call.',
            },
            {
              name: 'toolContext',
              type: 'InferToolContext<TOOLS[toolName]>',
              description:
                'Tool-specific context object for the tool call that is about to execute. Narrowed to the context type of the individual tool, not the entire tool set.',
            },
          ],
        },
      ],
    },
    {
      name: 'onToolExecutionEnd',
      type: '(event: ToolExecutionEndEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        "Callback that is called right after a tool's execute function completes (or errors). The `toolOutput` field is a discriminated union: when `toolOutput.type` is `'tool-result'`, the `output` field contains the tool result; when `toolOutput.type` is `'tool-error'`, the `error` field contains the error. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).",
      properties: [
        {
          type: 'ToolExecutionEndEvent',
          parameters: [
            {
              name: 'callId',
              type: 'string',
              description:
                'Unique identifier for this generation call, used to correlate events.',
            },
            {
              name: 'toolCall',
              type: 'TypedToolCall<TOOLS>',
              description:
                'The full tool call object containing toolName, toolCallId, input, and metadata.',
            },
            {
              name: 'toolExecutionMs',
              type: 'number',
              description:
                'The wall-clock duration of the tool execution in milliseconds.',
            },
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              description:
                'Messages that were sent to the language model to initiate the response that contained the tool call. Does not include the system prompt nor the assistant response that contained the tool call.',
            },
            {
              name: 'toolContext',
              type: 'InferToolContext<TOOLS[toolName]>',
              description:
                'Tool-specific context object for the tool call that just completed. Narrowed to the context type of the individual tool, not the entire tool set.',
            },
            {
              name: 'toolOutput',
              type: 'ToolOutput<TOOLS>',
              description:
                "Discriminated union representing the tool execution result. When `type` is `'tool-result'`, the `output` field contains the tool's return value. When `type` is `'tool-error'`, the `error` field contains the error.",
            },
          ],
        },
      ],
    },
    {
      name: 'experimental_onToolCallStart',
      type: '(event: ToolExecutionStartEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        'Deprecated. Use `onToolExecutionStart` instead. This alias is only used as a fallback when `onToolExecutionStart` is not provided.',
    },
    {
      name: 'experimental_onToolCallFinish',
      type: '(event: ToolExecutionEndEvent) => PromiseLike<void> | void',
      isOptional: true,
      description:
        'Deprecated. Use `onToolExecutionEnd` instead. This alias is only used as a fallback when `onToolExecutionEnd` is not provided.',
    },
  ]}
/>

### Returns

<PropertiesTable
  content={[
    {
      name: 'content',
      type: 'Promise<Array<ContentPart<TOOLS>>>',
      description:
        'The content that was generated in all steps. Automatically consumes the stream.',
    },
    {
      name: 'finishReason',
      type: "PromiseLike<'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'>",
      description:
        'The reason why the generation finished. Automatically consumes the stream.',
    },
    {
      name: 'rawFinishReason',
      type: 'PromiseLike<string | undefined>',
      description:
        'The raw reason why the generation finished (from the provider).',
    },
    {
      name: 'usage',
      type: 'Promise<LanguageModelUsage>',
      description:
        'The total token usage of the generated response. When there are multiple steps, the usage is the sum of all step usages. Automatically consumes the stream.',
      properties: [
        {
          type: 'LanguageModelUsage',
          parameters: [
            {
              name: 'inputTokens',
              type: 'number | undefined',
              description: 'The number of input (prompt) tokens used.',
            },
            {
              name: 'outputTokens',
              type: 'number | undefined',
              description: 'The number of output (completion) tokens used.',
            },
            {
              name: 'totalTokens',
              type: 'number | undefined',
              description:
                'The total number of tokens as reported by the provider. This number might be different from the sum of inputTokens and outputTokens and e.g. include reasoning tokens or other overhead.',
            },
          ],
        },
      ],
    },
    {
      name: 'totalUsage',
      type: 'Promise<LanguageModelUsage>',
      description: 'Deprecated. Use usage instead. The total token usage of the generated response. When there are multiple steps, the usage is the sum of all step usages. Automatically consumes the stream.',
      properties: [
                  {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description: 'The total number of input (prompt) tokens used.',
                    },
                    {
                      name: 'inputTokenDetails',
                      type: 'LanguageModelInputTokenDetails',
                      description:
                        'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
                      properties: [
                        {
                          type: 'LanguageModelInputTokenDetails',
                          parameters: [
                            {
                              name: 'noCacheTokens',
                              type: 'number | undefined',
                              description:
                                'The number of non-cached input (prompt) tokens used.',
                            },
                            {
                              name: 'cacheReadTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens read.',
                            },
                            {
                              name: 'cacheWriteTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens written.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description: 'The number of total output (completion) tokens used.',
                    },
                    {
                      name: 'outputTokenDetails',
                      type: 'LanguageModelOutputTokenDetails',
                      description:
                        'Detailed information about the output (completion) tokens.',
                      properties: [
                        {
                          type: 'LanguageModelOutputTokenDetails',
                          parameters: [
                            {
                              name: 'textTokens',
                              type: 'number | undefined',
                              description: 'The number of text tokens used.',
                            },
                            {
                              name: 'reasoningTokens',
                              type: 'number | undefined',
                              description: 'The number of reasoning tokens used.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description: 'The total number of tokens used.',
                    },
                    {
                      name: 'raw',
                      type: 'object | undefined',
                      isOptional: true,
                      description: 'Raw usage information from the provider. This is the provider\'s original usage information and may include additional fields.',
                    },
                  ],
                },
      ],
    },
    {
      name: 'providerMetadata',
      type: 'Promise<ProviderMetadata | undefined>',
      description:
        'Deprecated. Use `finalStep.providerMetadata` instead. Additional provider-specific metadata from the final step. Metadata is passed through from the provider to the AI SDK and enables provider-specific results that can be fully encapsulated in the provider.',
    },
    {
      name: 'text',
      type: 'Promise<string>',
      description:
        'The full text that has been generated. Automatically consumes the stream.',
    },
    {
      name: 'reasoning',
      type: 'Promise<Array<ReasoningOutput | ReasoningFileOutput>>',
      description:
        'Deprecated. Use `finalStep.reasoning` instead. The full reasoning that the model has generated in the final step. Automatically consumes the stream.',
      properties: [
        {
          type: 'ReasoningOutput',
          parameters: [
            {
              name: 'type',
              type: "'reasoning'",
              description: 'The type of the message part.',
            },
            {
              name: 'text',
              type: 'string',
              description: 'The reasoning text.',
            },
            {
              name: 'providerMetadata',
              type: 'SharedV2ProviderMetadata',
              isOptional: true,
              description: 'Additional provider metadata.',
            },
          ],
        },
        {
          type: 'ReasoningFileOutput',
          parameters: [
            {
              name: 'type',
              type: "'reasoning-file'",
              description: 'The type of the message part.',
            },
            {
              name: 'file',
              type: 'GeneratedFile',
              description: 'The generated file.',
            },
            {
              name: 'providerMetadata',
              type: 'SharedV2ProviderMetadata',
              isOptional: true,
              description: 'Additional provider metadata.',
            },
          ],
        },
      ],
    },
    {
      name: 'reasoningText',
      type: 'Promise<string | undefined>',
      description:
        'Deprecated. Use `finalStep.reasoningText` instead. The reasoning text that the model has generated in the final step. Can be undefined if the model has only generated text. Automatically consumes the stream.',
    },
    {
      name: 'sources',
      type: 'Promise<Array<Source>>',
      description:
        'Sources that have been used as input to generate the response. For multi-step generation, the sources are accumulated from all steps. Automatically consumes the stream.',
      properties: [
        {
          type: 'Source',
          parameters: [
            {
              name: 'sourceType',
              type: "'url'",
              description:
                'A URL source. This is return by web search RAG models.',
            },
            {
              name: 'id',
              type: 'string',
              description: 'The ID of the source.',
            },
            {
              name: 'url',
              type: 'string',
              description: 'The URL of the source.',
            },
            {
              name: 'title',
              type: 'string',
              isOptional: true,
              description: 'The title of the source.',
            },
            {
              name: 'providerMetadata',
              type: 'SharedV2ProviderMetadata',
              isOptional: true,
              description: 'Additional provider metadata for the source.',
            },
          ],
        },
      ],
    },
    {
      name: 'files',
      type: 'Promise<Array<GeneratedFile>>',
      description:
        'Files that were generated in all steps. Automatically consumes the stream.',
      properties: [
        {
          type: 'GeneratedFile',
          parameters: [
            {
              name: 'base64',
              type: 'string',
              description: 'File as a base64 encoded string.',
            },
            {
              name: 'uint8Array',
              type: 'Uint8Array',
              description: 'File as a Uint8Array.',
            },
            {
              name: 'mediaType',
              type: 'string',
              description: 'The IANA media type of the file.',
            },
          ],
        },
      ],
    },
    {
      name: 'toolCalls',
      type: 'Promise<TypedToolCall<TOOLS>[]>',
      description:
        'The tool calls that have been executed in all steps. Automatically consumes the stream.',
    },
    {
      name: 'toolResults',
      type: 'Promise<TypedToolResult<TOOLS>[]>',
      description:
        'The tool results that have been generated in all steps. Resolved when all tool executions are finished.',
    },
    {
      name: 'staticToolCalls',
      type: 'PromiseLike<Array<StaticToolCall<TOOLS>>>',
      description: 'The static tool calls that have been executed in all steps.',
    },
    {
      name: 'dynamicToolCalls',
      type: 'PromiseLike<Array<DynamicToolCall>>',
      description: 'The dynamic tool calls that have been executed in all steps.',
    },
    {
      name: 'staticToolResults',
      type: 'PromiseLike<Array<StaticToolResult<TOOLS>>>',
      description: 'The static tool results that have been generated in all steps.',
    },
    {
      name: 'dynamicToolResults',
      type: 'PromiseLike<Array<DynamicToolResult>>',
      description: 'The dynamic tool results that have been generated in all steps.',
    },
    {
      name: 'request',
      type: 'Promise<LanguageModelRequestMetadata>',
      description:
        'Deprecated. Use `finalStep.request` instead. Additional request information from the final step. Automatically consumes the stream.',
      properties: [
        {
          type: 'LanguageModelRequestMetadata',
          parameters: [
            {
              name: 'messages',
              type: 'Array<ModelMessage>',
              isOptional: true,
              description:
                'The input messages that were sent to the model for this step. Undefined by default unless requestMessages is set to true.',
            },
            {
              name: 'body',
              type: 'unknown',
              isOptional: true,
              description:
                'Request HTTP body that was sent to the provider API.',
            },
          ],
        },
      ],
    },
    {
      name: 'response',
      type: 'Promise<LanguageModelResponseMetadata>',
      description:
        'Deprecated. Use `finalStep.response` instead. Additional response information from the final step. Automatically consumes the stream.',
      properties: [
        {
          type: 'LanguageModelResponseMetadata',
          parameters: [
            {
              name: 'id',
              type: 'string',
              description:
                'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
            },
            {
              name: 'modelId',
              type: 'string',
              description:
                'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
            },
            {
              name: 'timestamp',
              type: 'Date',
              description:
                'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
            },
            {
              name: 'headers',
              isOptional: true,
              type: 'Record<string, string>',
              description: 'Optional response headers.',
            },
            {
              name: 'body',
              isOptional: true,
              type: 'unknown',
              description:
                'Response body (available only for providers that use HTTP requests).',
            },
            {
              name: 'messages',
              type: 'Array<ResponseMessage>',
              description:
                'The response messages generated during the final step. It consists of an assistant message, potentially containing tool calls. When there are tool results in the final step, there is an additional tool message with the available tool results. If there are tools that do not have execute functions, they are not included in the tool results and need to be added separately.',
            },
          ],
        },
      ],
    },
    {
      name: 'warnings',
      type: 'Promise<Warning[] | undefined>',
      description:
        'Warnings from the model provider (e.g. unsupported settings) in all steps.',
    },
    {
      name: 'responseMessages',
      type: 'Promise<Array<ResponseMessage>>',
      description:
        'The accumulated response messages of all steps that were generated during the call.',
    },
    {
      name: 'steps',
      type: 'Promise<Array<StepResult>>',
      description:
        'Response information for every step. You can use this to get information about intermediate steps, such as the tool calls or the response headers.',
      properties: [
        {
          type: 'StepResult',
          parameters: [
            {
              name: 'stepType',
              type: '"initial" | "continue" | "tool-result"',
              description:
                'The type of step. The first step is always an "initial" step, and subsequent steps are either "continue" steps or "tool-result" steps.',
            },
            {
              name: 'text',
              type: 'string',
              description: 'The generated text by the model.',
            },
            {
              name: 'reasoning',
              type: 'string | undefined',
              description:
                'The reasoning text of the model (only available for some models).',
            },
            {
              name: 'sources',
              type: 'Array<Source>',
              description: 'Sources that have been used as input.',
              properties: [
                {
                  type: 'Source',
                  parameters: [
                    {
                      name: 'sourceType',
                      type: "'url'",
                      description:
                        'A URL source. This is return by web search RAG models.',
                    },
                    {
                      name: 'id',
                      type: 'string',
                      description: 'The ID of the source.',
                    },
                    {
                      name: 'url',
                      type: 'string',
                      description: 'The URL of the source.',
                    },
                    {
                      name: 'title',
                      type: 'string',
                      isOptional: true,
                      description: 'The title of the source.',
                    },
                    {
                      name: 'providerMetadata',
                      type: 'SharedV2ProviderMetadata',
                      isOptional: true,
                      description:
                        'Additional provider metadata for the source.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'files',
              type: 'Array<GeneratedFile>',
              description: 'Files that were generated in this step.',
              properties: [
                {
                  type: 'GeneratedFile',
                  parameters: [
                    {
                      name: 'base64',
                      type: 'string',
                      description: 'File as a base64 encoded string.',
                    },
                    {
                      name: 'uint8Array',
                      type: 'Uint8Array',
                      description: 'File as a Uint8Array.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'toolCalls',
              type: 'array',
              description: 'A list of tool calls made by the model.',
            },
            {
              name: 'toolResults',
              type: 'array',
              description:
                'A list of tool results returned as responses to earlier tool calls.',
            },
            {
              name: 'finishReason',
              type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'",
              description: 'The reason the model finished generating the text.',
            },
            {
              name: 'rawFinishReason',
              type: 'string | undefined',
              description:
                'The raw reason why the generation finished (from the provider).',
            },
            {
              name: 'usage',
              type: 'LanguageModelUsage',
              description: 'The token usage of the generated text.',
              properties: [
                {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description: 'The total number of input (prompt) tokens used.',
                    },
                    {
                      name: 'inputTokenDetails',
                      type: 'LanguageModelInputTokenDetails',
                      description:
                        'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
                      properties: [
                        {
                          type: 'LanguageModelInputTokenDetails',
                          parameters: [
                            {
                              name: 'noCacheTokens',
                              type: 'number | undefined',
                              description:
                                'The number of non-cached input (prompt) tokens used.',
                            },
                            {
                              name: 'cacheReadTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens read.',
                            },
                            {
                              name: 'cacheWriteTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens written.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description: 'The number of total output (completion) tokens used.',
                    },
                    {
                      name: 'outputTokenDetails',
                      type: 'LanguageModelOutputTokenDetails',
                      description:
                        'Detailed information about the output (completion) tokens.',
                      properties: [
                        {
                          type: 'LanguageModelOutputTokenDetails',
                          parameters: [
                            {
                              name: 'textTokens',
                              type: 'number | undefined',
                              description: 'The number of text tokens used.',
                            },
                            {
                              name: 'reasoningTokens',
                              type: 'number | undefined',
                              description: 'The number of reasoning tokens used.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description: 'The total number of tokens used.',
                    },
                    {
                      name: 'raw',
                      type: 'object | undefined',
                      isOptional: true,
                      description: 'Raw usage information from the provider. This is the provider\'s original usage information and may include additional fields.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'request',
              type: 'RequestMetadata',
              isOptional: true,
              description: 'Request metadata.',
              properties: [
                {
                  type: 'RequestMetadata',
                  parameters: [
                    {
                      name: 'messages',
                      type: 'Array<ModelMessage>',
                      isOptional: true,
                      description:
                        'The input messages that were sent to the model for this step. Undefined by default unless requestMessages is set to true.',
                    },
                    {
                      name: 'body',
                      type: 'unknown',
                      isOptional: true,
                      description:
                        'Request HTTP body that was sent to the provider API.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'response',
              type: 'ResponseMetadata',
              isOptional: true,
              description: 'Response metadata.',
              properties: [
                {
                  type: 'ResponseMetadata',
                  parameters: [
                    {
                      name: 'id',
                      type: 'string',
                      description:
                        'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
                    },
                    {
                      name: 'modelId',
                      type: 'string',
                      description:
                        'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
                    },
                    {
                      name: 'timestamp',
                      type: 'Date',
                      description:
                        'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
                    },
                    {
                      name: 'headers',
                      isOptional: true,
                      type: 'Record<string, string>',
                      description: 'Optional response headers.',
                    },
                    {
                      name: 'messages',
                      type: 'Array<ResponseMessage>',
                      description:
                        'The response messages generated during this step. It consists of an assistant message, potentially containing tool calls. When there are tool results in this step, there is an additional tool message with the available tool results. If there are tools that do not have execute functions, they are not included in the tool results and need to be added separately.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'warnings',
              type: 'Warning[] | undefined',
              description:
                'Warnings from the model provider (e.g. unsupported settings).',
            },
            {
              name: 'isContinued',
              type: 'boolean',
              description:
                'True when there will be a continuation step with a continuation text.',
            },
            {
              name: 'providerMetadata',
              type: 'Record<string,JSONObject> | undefined',
              isOptional: true,
              description:
                'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
            },
          ],
        },
      ],
    },
    {
      name: 'textStream',
      type: 'AsyncIterableStream<string>',
      description:
        'A text stream that returns only the generated text deltas. You can use it as either an AsyncIterable or a ReadableStream. When an error occurs, the stream will throw the error.',
    },
    {
      name: 'finalStep',
      type: 'Promise<StepResult>',
      description:
        'The final step. This is a shortcut for `steps.at(-1)`. Automatically consumes the stream.',
    },
    {
      name: 'stream',
      type: 'AsyncIterable<TextStreamPart<TOOLS>> & ReadableStream<TextStreamPart<TOOLS>>',
      description:
        'A stream with all events, including text deltas, tool calls, tool results, and errors. You can use it as either an AsyncIterable or a ReadableStream. Only errors that stop the stream, such as network errors, are thrown.',
      properties: [
        {
          type: 'TextStreamPart',
          description: 'Text content part from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'text'",
              description: 'The type to identify the object as text.',
            },
            {
              name: 'text',
              type: 'string',
              description: 'The text content.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          description: 'Reasoning content part from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'reasoning'",
              description: 'The type to identify the object as reasoning.',
            },
            {
              name: 'text',
              type: 'string',
              description: 'The reasoning text.',
            },
            {
              name: 'providerMetadata',
              type: 'ProviderMetadata',
              isOptional: true,
              description: 'Optional provider metadata for the reasoning.',
            },
          ],
        },

        {
          type: 'TextStreamPart',
          description: 'Source content part from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'source'",
              description: 'The type to identify the object as source.',
            },
            {
              name: 'sourceType',
              type: "'url'",
              description: 'A URL source. This is returned by web search RAG models.',
            },
            {
              name: 'id',
              type: 'string',
              description: 'The ID of the source.',
            },
            {
              name: 'url',
              type: 'string',
              description: 'The URL of the source.',
            },
            {
              name: 'title',
              type: 'string',
              isOptional: true,
              description: 'The title of the source.',
            },
            {
              name: 'providerMetadata',
              type: 'ProviderMetadata',
              isOptional: true,
              description: 'Additional provider metadata for the source.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          description: 'File content part from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'file'",
              description: 'The type to identify the object as file.',
            },
            {
              name: 'file',
              type: 'GeneratedFile',
              description: 'The file.',
              properties: [
                {
                  type: 'GeneratedFile',
                  parameters: [
                    {
                      name: 'base64',
                      type: 'string',
                      description: 'File as a base64 encoded string.',
                    },
                    {
                      name: 'uint8Array',
                      type: 'Uint8Array',
                      description: 'File as a Uint8Array.',
                    },
                    {
                      name: 'mediaType',
                      type: 'string',
                      description: 'The IANA media type of the file.',
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          type: 'TextStreamPart',
          description: 'Custom content part from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'custom'",
              description: 'The type to identify the object as custom content.',
            },
            {
              name: 'kind',
              type: 'string',
              description:
                'The kind of custom content, in the format {provider}.{provider-type} (e.g. openai.compaction).',
            },
            {
              name: 'providerMetadata',
              type: 'ProviderMetadata',
              isOptional: true,
              description: 'Optional provider metadata for the custom content.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          description: 'Tool call from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'tool-call'",
              description: 'The type to identify the object as tool call.',
            },
            {
              name: 'toolCallId',
              type: 'string',
              description: 'The id of the tool call.',
            },
            {
              name: 'toolName',
              type: 'string',
              description:
                'The name of the tool, which typically would be the name of the function.',
            },
            {
              name: 'input',
              type: 'object based on tool parameters',
              description:
                'Parameters generated by the model to be used by the tool. The type is inferred from the tool definition.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'tool-call-streaming-start'",
              description:
                'Indicates the start of a tool call streaming. Only available when streaming tool calls.',
            },
            {
              name: 'toolCallId',
              type: 'string',
              description: 'The id of the tool call.',
            },
            {
              name: 'toolName',
              type: 'string',
              description:
                'The name of the tool, which typically would be the name of the function.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'tool-call-delta'",
              description:
                'The type to identify the object as tool call delta. Only available when streaming tool calls.',
            },
            {
              name: 'toolCallId',
              type: 'string',
              description: 'The id of the tool call.',
            },
            {
              name: 'toolName',
              type: 'string',
              description:
                'The name of the tool, which typically would be the name of the function.',
            },
            {
              name: 'argsTextDelta',
              type: 'string',
              description: 'The text delta of the tool call arguments.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          description: 'Tool result from ContentPart<TOOLS>',
          parameters: [
            {
              name: 'type',
              type: "'tool-result'",
              description: 'The type to identify the object as tool result.',
            },
            {
              name: 'toolCallId',
              type: 'string',
              description: 'The id of the tool call.',
            },
            {
              name: 'toolName',
              type: 'string',
              description:
                'The name of the tool, which typically would be the name of the function.',
            },
            {
              name: 'input',
              type: 'object based on tool parameters',
              description:
                'Parameters that were passed to the tool. The type is inferred from the tool definition.',
            },
            {
              name: 'output',
              type: 'tool execution return type',
              description:
                'The result returned by the tool after execution has completed. The type is inferred from the tool execute function return type.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'start-step'",
              description: 'Indicates the start of a new step in the stream.',
            },
            {
              name: 'request',
              type: 'LanguageModelRequestMetadata',
              description:
                'Information about the request that was sent to the language model provider.',
              properties: [
                {
                  type: 'LanguageModelRequestMetadata',
                  parameters: [
                    {
                      name: 'messages',
                      type: 'Array<ModelMessage>',
                      description:
                        'The input messages that were sent to the model for this step.',
                    },
                    {
                      name: 'body',
                      type: 'unknown',
                      isOptional: true,
                      description:
                        'Request HTTP body that was sent to the provider API.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'warnings',
              type: 'Warning[]',
              description:
                'Warnings from the model provider (e.g. unsupported settings).',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'finish-step'",
              description:
                'Indicates the end of the current step in the stream.',
            },
            {
              name: 'response',
              type: "Omit<LanguageModelResponseMetadata, 'messages' | 'body'>",
              description:
                'Response metadata from the language model provider. `messages` and `body` are not included on `finish-step` stream parts.',
              properties: [
                {
                  type: 'LanguageModelResponseMetadata',
                  parameters: [
                    {
                      name: 'id',
                      type: 'string',
                      description:
                        'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
                    },
                    {
                      name: 'modelId',
                      type: 'string',
                      description:
                        'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
                    },
                    {
                      name: 'timestamp',
                      type: 'Date',
                      description:
                        'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
                    },
                    {
                      name: 'headers',
                      type: 'Record<string, string>',
                      description: 'The response headers.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'usage',
              type: 'LanguageModelUsage',
              description: 'The token usage of the generated text.',
              properties: [
                 {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description: 'The total number of input (prompt) tokens used.',
                    },
                    {
                      name: 'inputTokenDetails',
                      type: 'LanguageModelInputTokenDetails',
                      description:
                        'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
                      properties: [
                        {
                          type: 'LanguageModelInputTokenDetails',
                          parameters: [
                            {
                              name: 'noCacheTokens',
                              type: 'number | undefined',
                              description:
                                'The number of non-cached input (prompt) tokens used.',
                            },
                            {
                              name: 'cacheReadTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens read.',
                            },
                            {
                              name: 'cacheWriteTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens written.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description: 'The number of total output (completion) tokens used.',
                    },
                    {
                      name: 'outputTokenDetails',
                      type: 'LanguageModelOutputTokenDetails',
                      description:
                        'Detailed information about the output (completion) tokens.',
                      properties: [
                        {
                          type: 'LanguageModelOutputTokenDetails',
                          parameters: [
                            {
                              name: 'textTokens',
                              type: 'number | undefined',
                              description: 'The number of text tokens used.',
                            },
                            {
                              name: 'reasoningTokens',
                              type: 'number | undefined',
                              description: 'The number of reasoning tokens used.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description: 'The total number of tokens used.',
                    },
                    {
                      name: 'raw',
                      type: 'object | undefined',
                      isOptional: true,
                      description: 'Raw usage information from the provider. This is the provider\'s original usage information and may include additional fields.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'performance',
              type: 'StepResultPerformance',
              description: 'Timing and throughput metrics for the step.',
              properties: [
                {
                  type: 'StepResultPerformance',
                  parameters: [
                    {
              name: 'effectiveOutputTokensPerSecond',
                      type: 'number',
                      description:
                'Effective number of output tokens per second over the full language model response.',
            },
            {
              name: 'outputTokensPerSecond',
              type: 'number | undefined',
              description:
                'Number of output tokens per second after the first generated output chunk was received. Only available for streaming steps.',
            },
            {
              name: 'inputTokensPerSecond',
              type: 'number | undefined',
              description:
                'Number of input tokens processed per second before the first generated output chunk was received. Only available for streaming steps.',
            },
            {
              name: 'effectiveTotalTokensPerSecond',
              type: 'number',
              description:
                'Effective number of input and output tokens per second over the full language model response.',
                    },
                    {
                      name: 'stepTimeMs',
                      type: 'number',
                      description:
                        'Total time spent on the step, including language model response time and tool execution time, in milliseconds.',
                    },
                    {
                      name: 'responseTimeMs',
                      type: 'number',
                      description:
                        'Time spent waiting for the language model response in milliseconds.',
                    },
                    {
                      name: 'toolExecutionMs',
                      type: 'Readonly<Record<string, number>>',
                      description:
                        'Time spent executing each client-side tool call in the step in milliseconds, keyed by tool call ID.',
                    },
                    {
                      name: 'timeToFirstOutputMs',
                      type: 'number | undefined',
                      description:
                        'Time until the first generated output chunk was received in milliseconds. Only available for streaming steps.',
                    },
                    {
                      name: 'timeBetweenOutputChunksMs',
                      type: 'OutputChunkTimingStats | undefined',
                      description:
                        'Timing statistics for the gaps between generated output chunks in milliseconds. Only available for streaming steps with at least two output chunks.',
                    },
                  ],
                },
              ],
            },
            {
              name: 'finishReason',
              type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'",
              description: 'The reason the model finished generating the text.',
            },
            {
              name: 'rawFinishReason',
              type: 'string | undefined',
              description:
                'The raw reason why the generation finished (from the provider).',
            },
            {
              name: 'providerMetadata',
              type: 'ProviderMetadata | undefined',
              isOptional: true,
              description:
                'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'start'",
              description: 'Indicates the start of the stream.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'finish'",
              description: 'The type to identify the object as finish.',
            },
            {
              name: 'finishReason',
              type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'",
              description: 'The reason the model finished generating the text.',
            },
            {
              name: 'rawFinishReason',
              type: 'string | undefined',
              description:
                'The raw reason why the generation finished (from the provider).',
            },
            {
              name: 'totalUsage',
              type: 'LanguageModelUsage',
              description: 'The total token usage of the generated text.',
              properties: [
                {
                  type: 'LanguageModelUsage',
                  parameters: [
                    {
                      name: 'inputTokens',
                      type: 'number | undefined',
                      description: 'The total number of input (prompt) tokens used.',
                    },
                    {
                      name: 'inputTokenDetails',
                      type: 'LanguageModelInputTokenDetails',
                      description:
                        'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
                      properties: [
                        {
                          type: 'LanguageModelInputTokenDetails',
                          parameters: [
                            {
                              name: 'noCacheTokens',
                              type: 'number | undefined',
                              description:
                                'The number of non-cached input (prompt) tokens used.',
                            },
                            {
                              name: 'cacheReadTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens read.',
                            },
                            {
                              name: 'cacheWriteTokens',
                              type: 'number | undefined',
                              description:
                                'The number of cached input (prompt) tokens written.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'outputTokens',
                      type: 'number | undefined',
                      description: 'The number of total output (completion) tokens used.',
                    },
                    {
                      name: 'outputTokenDetails',
                      type: 'LanguageModelOutputTokenDetails',
                      description:
                        'Detailed information about the output (completion) tokens.',
                      properties: [
                        {
                          type: 'LanguageModelOutputTokenDetails',
                          parameters: [
                            {
                              name: 'textTokens',
                              type: 'number | undefined',
                              description: 'The number of text tokens used.',
                            },
                            {
                              name: 'reasoningTokens',
                              type: 'number | undefined',
                              description: 'The number of reasoning tokens used.',
                            },
                          ],
                        },
                      ],
                    },
                    {
                      name: 'totalTokens',
                      type: 'number | undefined',
                      description: 'The total number of tokens used.',
                    },
                    {
                      name: 'raw',
                      type: 'object | undefined',
                      isOptional: true,
                      description: 'Raw usage information from the provider. This is the provider\'s original usage information and may include additional fields.',
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'reasoning-part-finish'",
              description: 'Indicates the end of a reasoning part.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'error'",
              description: 'The type to identify the object as error.',
            },
            {
              name: 'error',
              type: 'unknown',
              description:
                'Describes the error that may have occurred during execution.',
            },
          ],
        },
        {
          type: 'TextStreamPart',
          parameters: [
            {
              name: 'type',
              type: "'abort'",
              description: 'The type to identify the object as abort.',
            },
            {
              name: 'reason',
              type: 'unknown',
              isOptional: true,
              description:
                'Optional abort reason (from AbortSignal.reason) when the stream is aborted.',
            },
          ],
        },
      ],
    },
    {
      name: 'fullStream',
      type: 'AsyncIterable<TextStreamPart<TOOLS>> & ReadableStream<TextStreamPart<TOOLS>>',
      description:
        'Deprecated. Use `stream` instead. A stream with all events, including text deltas, tool calls, tool results, and errors.',
    },
    {
      name: 'partialOutputStream',
      type: 'AsyncIterableStream<PARTIAL_OUTPUT>',
      description:
        'A stream of partial parsed outputs. It uses the `output` specification. AsyncIterableStream is defined as AsyncIterable<T> & ReadableStream<T>.',
    },
    {
      name: 'elementStream',
      type: 'AsyncIterableStream<ELEMENT_OUTPUT>',
      description:
        'A stream of individual array elements as they complete. Only available when using `output: Output.array()`. Each element is complete and validated against the element schema. AsyncIterableStream is defined as AsyncIterable<T> & ReadableStream<T>.',
    },
    {
      name: 'output',
      type: 'Promise<COMPLETE_OUTPUT>',
      description:
        'The complete parsed output. It uses the `output` specification.',
    },
    {
      name: 'consumeStream',
      type: '(options?: ConsumeStreamOptions) => Promise<void>',
      description:
        'Consumes the stream without processing the parts. This is useful to force the stream to finish. If an error occurs, it is passed to the optional `onError` callback.',
      properties: [
        {
          type: 'ConsumeStreamOptions',
          parameters: [
            {
              name: 'onError',
              type: '(error: unknown) => void',
              isOptional: true,
              description: 'The error callback.',
            },
          ],
        },
      ],
    },
    {
      name: 'toUIMessageStream',
      type: '(options?: UIMessageStreamOptions) => AsyncIterableStream<UIMessageChunk>',
      description:
        'Converts the result to a UI message stream. Returns an AsyncIterableStream that can be used as both an AsyncIterable and a ReadableStream. The stream includes tool approval request and response chunks, including automatic approval metadata when available.',
      properties: [
        {
          type: 'UIMessageStreamOptions',
          parameters: [
            {
              name: 'originalMessages',
              type: 'UIMessage[]',
              isOptional: true,
              description: 'The original messages.',
            },
            {
              name: 'onFinish',
              type: '(options: { messages: UIMessage[]; isContinuation: boolean; responseMessage: UIMessage; isAborted: boolean; }) => void',
              isOptional: true,
              description: 'Callback function called when the stream finishes. Provides the updated list of UI messages, whether the response is a continuation, the response message, and whether the stream was aborted.',
            },
            {
              name: 'messageMetadata',
              type: '(options: { part: TextStreamPart<TOOLS> & { type: "start" | "finish" | "start-step" | "finish-step"; }; }) => unknown',
              isOptional: true,
              description: 'Extracts message metadata that will be sent to the client. Called on start and finish events.',
            },
            {
              name: 'sendReasoning',
              type: 'boolean',
              isOptional: true,
              description:
                'Send reasoning parts to the client. Defaults to false.',
            },
            {
              name: 'sendSources',
              type: 'boolean',
              isOptional: true,
              description:
                'Send source parts to the client. Defaults to false.',
            },
            {
              name: 'sendFinish',
              type: 'boolean',
              isOptional: true,
              description:
                'Send the finish event to the client. Defaults to true.',
            },
            {
              name: 'sendStart',
              type: 'boolean',
              isOptional: true,
              description:
                'Send the message start event to the client. Set to false if you are using additional streamText calls and the message start event has already been sent. Defaults to true.',
            },
            {
              name: 'onError',
              type: '(error: unknown) => string',
              isOptional: true,
              description:
                'Process an error, e.g. to log it. Returns error message to include in the data stream. Defaults to () => "An error occurred."',
            },
            {
              name: 'consumeSseStream',
              type: '(stream: ReadableStream) => Promise<void>',
              isOptional: true,
              description:
                'Function to consume the SSE stream. Required for proper abort handling in UI message streams. Use the `consumeStream` function from the AI SDK.',
            },
          ],
        },
      ],
    },
    {
      name: 'pipeUIMessageStreamToResponse',
      type: '(response: ServerResponse, options?: ResponseInit & UIMessageStreamOptions) => void',
      description:
        'Writes UI message stream output to a Node.js response-like object.',
      properties: [
        {
          type: 'ResponseInit & UIMessageStreamOptions',
          parameters: [
            {
              name: 'status',
              type: 'number',
              isOptional: true,
              description: 'The response status code.',
            },
            {
              name: 'statusText',
              type: 'string',
              isOptional: true,
              description: 'The response status text.',
            },
            {
              name: 'headers',
              type: 'HeadersInit',
              isOptional: true,
              description: 'The response headers.',
            },
          ],
        },
      ],
    },
    {
      name: 'pipeTextStreamToResponse',
      type: '(response: ServerResponse, init?: ResponseInit) => void',
      description:
        'Writes text delta output to a Node.js response-like object. It sets a `Content-Type` header to `text/plain; charset=utf-8` and writes each text delta as a separate chunk.',
      properties: [
        {
          type: 'ResponseInit',
          parameters: [
            {
              name: 'status',
              type: 'number',
              isOptional: true,
              description: 'The response status code.',
            },
            {
              name: 'statusText',
              type: 'string',
              isOptional: true,
              description: 'The response status text.',
            },
            {
              name: 'headers',
              type: 'Record<string, string>',
              isOptional: true,
              description: 'The response headers.',
            },
          ],
        },
      ],
    },
    {
      name: 'toUIMessageStreamResponse',
      type: '(options?: ResponseInit & UIMessageStreamOptions) => Response',
      description:
        'Converts the result to a streamed response object with a UI message stream.',
      properties: [
        {
          type: 'ResponseInit & UIMessageStreamOptions',
          parameters: [
            {
              name: 'status',
              type: 'number',
              isOptional: true,
              description: 'The response status code.',
            },
            {
              name: 'statusText',
              type: 'string',
              isOptional: true,
              description: 'The response status text.',
            },
            {
              name: 'headers',
              type: 'HeadersInit',
              isOptional: true,
              description: 'The response headers.',
            },
          ],
        },
      ],
    },
    {
      name: 'toTextStreamResponse',
      type: '(init?: ResponseInit) => Response',
      description:
        'Creates a simple text stream response. Each text delta is encoded as UTF-8 and sent as a separate chunk. Non-text-delta events are ignored.',
      properties: [
        {
          type: 'ResponseInit',
          parameters: [
            {
              name: 'status',
              type: 'number',
              isOptional: true,
              description: 'The response status code.',
            },
            {
              name: 'statusText',
              type: 'string',
              isOptional: true,
              description: 'The response status text.',
            },
            {
              name: 'headers',
              type: 'Record<string, string>',
              isOptional: true,
              description: 'The response headers.',
            },
          ],
        },
      ],
    },

]}
/>

## Types

### `ActiveTools`

```ts
type ActiveTools<TOOLS extends ToolSet> =
  | ReadonlyArray<keyof TOOLS & string>
  | undefined;
```

Limits a generation step to the listed tool names. `undefined` means no tool restriction is applied.

## Examples

<ExampleLinks
  examples={[
    {
      title: 'Learn to stream text generated by a language model in Next.js',
      link: '/examples/next-app/basics/streaming-text-generation',
    },
    {
      title:
        'Learn to stream chat completions generated by a language model in Next.js',
      link: '/examples/next-app/chat/stream-chat-completion',
    },
    {
      title: 'Learn to stream text generated by a language model in Node.js',
      link: '/examples/node/generating-text/stream-text',
    },
    {
      title:
        'Learn to stream chat completions generated by a language model in Node.js',
      link: '/examples/node/generating-text/stream-text-with-chat-prompt',
    },
  ]}
/>


## Navigation

- [generateText](/v7/docs/reference/ai-sdk-core/generate-text)
- [streamText](/v7/docs/reference/ai-sdk-core/stream-text)
- [embed](/v7/docs/reference/ai-sdk-core/embed)
- [embedMany](/v7/docs/reference/ai-sdk-core/embed-many)
- [rerank](/v7/docs/reference/ai-sdk-core/rerank)
- [generateImage](/v7/docs/reference/ai-sdk-core/generate-image)
- [transcribe](/v7/docs/reference/ai-sdk-core/transcribe)
- [generateSpeech](/v7/docs/reference/ai-sdk-core/generate-speech)
- [experimental_generateVideo](/v7/docs/reference/ai-sdk-core/generate-video)
- [uploadFile](/v7/docs/reference/ai-sdk-core/upload-file)
- [uploadSkill](/v7/docs/reference/ai-sdk-core/upload-skill)
- [Agent (Interface)](/v7/docs/reference/ai-sdk-core/agent)
- [ToolLoopAgent](/v7/docs/reference/ai-sdk-core/tool-loop-agent)
- [createAgentUIStream](/v7/docs/reference/ai-sdk-core/create-agent-ui-stream)
- [createAgentUIStreamResponse](/v7/docs/reference/ai-sdk-core/create-agent-ui-stream-response)
- [pipeAgentUIStreamToResponse](/v7/docs/reference/ai-sdk-core/pipe-agent-ui-stream-to-response)
- [tool](/v7/docs/reference/ai-sdk-core/tool)
- [dynamicTool](/v7/docs/reference/ai-sdk-core/dynamic-tool)
- [createMCPClient](/v7/docs/reference/ai-sdk-core/create-mcp-client)
- [MCP Apps](/v7/docs/reference/ai-sdk-core/mcp-apps)
- [Experimental_StdioMCPTransport](/v7/docs/reference/ai-sdk-core/mcp-stdio-transport)
- [jsonSchema](/v7/docs/reference/ai-sdk-core/json-schema)
- [zodSchema](/v7/docs/reference/ai-sdk-core/zod-schema)
- [valibotSchema](/v7/docs/reference/ai-sdk-core/valibot-schema)
- [Output](/v7/docs/reference/ai-sdk-core/output)
- [filterActiveTools](/v7/docs/reference/ai-sdk-core/filter-active-tools)
- [ModelMessage](/v7/docs/reference/ai-sdk-core/model-message)
- [UIMessage](/v7/docs/reference/ai-sdk-core/ui-message)
- [validateUIMessages](/v7/docs/reference/ai-sdk-core/validate-ui-messages)
- [safeValidateUIMessages](/v7/docs/reference/ai-sdk-core/safe-validate-ui-messages)
- [Experimental_Sandbox](/v7/docs/reference/ai-sdk-core/sandbox)
- [createProviderRegistry](/v7/docs/reference/ai-sdk-core/provider-registry)
- [customProvider](/v7/docs/reference/ai-sdk-core/custom-provider)
- [cosineSimilarity](/v7/docs/reference/ai-sdk-core/cosine-similarity)
- [wrapLanguageModel](/v7/docs/reference/ai-sdk-core/wrap-language-model)
- [wrapImageModel](/v7/docs/reference/ai-sdk-core/wrap-image-model)
- [LanguageModelV4Middleware](/v7/docs/reference/ai-sdk-core/language-model-v2-middleware)
- [extractReasoningMiddleware](/v7/docs/reference/ai-sdk-core/extract-reasoning-middleware)
- [simulateStreamingMiddleware](/v7/docs/reference/ai-sdk-core/simulate-streaming-middleware)
- [defaultSettingsMiddleware](/v7/docs/reference/ai-sdk-core/default-settings-middleware)
- [addToolInputExamplesMiddleware](/v7/docs/reference/ai-sdk-core/add-tool-input-examples-middleware)
- [extractJsonMiddleware](/v7/docs/reference/ai-sdk-core/extract-json-middleware)
- [isStepCount](/v7/docs/reference/ai-sdk-core/is-step-count)
- [hasToolCall](/v7/docs/reference/ai-sdk-core/has-tool-call)
- [isLoopFinished](/v7/docs/reference/ai-sdk-core/loop-finished)
- [simulateReadableStream](/v7/docs/reference/ai-sdk-core/simulate-readable-stream)
- [smoothStream](/v7/docs/reference/ai-sdk-core/smooth-stream)
- [generateId](/v7/docs/reference/ai-sdk-core/generate-id)
- [createIdGenerator](/v7/docs/reference/ai-sdk-core/create-id-generator)
- [DefaultGeneratedFile](/v7/docs/reference/ai-sdk-core/default-generated-file)


[Full Sitemap](/sitemap.md)
