@yamlresume/ai
    Preparing search index...

    Function generateText

    • Generate a text and call tools for a given prompt using a language model.

      This function does not stream the output. If you want to stream the output, use streamText instead.

      Type Parameters

      • TOOLS extends ToolSet
      • RUNTIME_CONTEXT extends Context = Context
      • OUTPUT extends Output<any, any, any> = Output<string, string, any>

      Parameters

      • model: (LanguageModelCallOptions & (RequestOptions<TOOLS> & Prompt)) & {
            tools?: TOOLS;
        } & ToolsContextSettings<TOOLS> & {
            _internal?: {
                generateCallId?: IdGenerator;
                generateId?: IdGenerator;
                now?: () => number;
            };
            activeTools?: readonly (NoInfer<keyof TOOLS> & string)[];
            experimental_download?: DownloadFunction;
            experimental_include?: GenerateTextInclude;
            experimental_onLanguageModelCallEnd?: OnLanguageModelCallEndCallback<
                NoInfer<TOOLS>,
            >;
            experimental_onLanguageModelCallStart?: OnLanguageModelCallStartCallback;
            experimental_onStart?: GenerateTextOnStartCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
                NoInfer<OUTPUT>,
            >;
            experimental_onStepStart?: GenerateTextOnStepStartCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
                NoInfer<OUTPUT>,
            >;
            experimental_onToolCallFinish?: OnToolExecutionEndCallback<NoInfer<TOOLS>>;
            experimental_onToolCallStart?: OnToolExecutionStartCallback<NoInfer<TOOLS>>;
            experimental_refineToolInput?: ToolInputRefinement<NoInfer<TOOLS>>;
            experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
            experimental_sandbox?: SandboxSession;
            experimental_telemetry?: TelemetryOptions<RUNTIME_CONTEXT, NoInfer<TOOLS>>;
            experimental_toolApprovalSecret?: string | Uint8Array<ArrayBufferLike>;
            experimental_toolCallers?: Experimental_ToolCallers<NoInfer<TOOLS>>;
            include?: GenerateTextInclude;
            model: LanguageModel;
            onEnd?: GenerateTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>;
            onFinish?: GenerateTextOnEndCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
            >;
            onLanguageModelCallEnd?: OnLanguageModelCallEndCallback<NoInfer<TOOLS>>;
            onLanguageModelCallStart?: OnLanguageModelCallStartCallback;
            onStart?: GenerateTextOnStartCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
                NoInfer<OUTPUT>,
            >;
            onStepEnd?: GenerateTextOnStepEndCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
            >;
            onStepFinish?: GenerateTextOnStepFinishCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
            >;
            onStepStart?: GenerateTextOnStepStartCallback<
                NoInfer<TOOLS>,
                NoInfer<RUNTIME_CONTEXT>,
                NoInfer<OUTPUT>,
            >;
            onToolExecutionEnd?: OnToolExecutionEndCallback<NoInfer<TOOLS>>;
            onToolExecutionStart?: OnToolExecutionStartCallback<NoInfer<TOOLS>>;
            output?: OUTPUT;
            prepareStep?: PrepareStepFunction<NoInfer<TOOLS>, RUNTIME_CONTEXT>;
            providerOptions?: ProviderOptions;
            repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
            runtimeContext?: RUNTIME_CONTEXT;
            stopWhen?: Arrayable<StopCondition<NoInfer<TOOLS>, RUNTIME_CONTEXT>>;
            telemetry?: TelemetryOptions<RUNTIME_CONTEXT, NoInfer<TOOLS>>;
            toolApproval?: ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT>;
            toolChoice?: ToolChoice<NoInfer<TOOLS>>;
            toolOrder?: readonly (NoInfer<keyof TOOLS> & string)[];
        }

        The language model to use.

        • Optional_internal?: { generateCallId?: IdGenerator; generateId?: IdGenerator; now?: () => number }

          Internal. For test use only. May change without notice.

        • OptionalactiveTools?: readonly (NoInfer<keyof TOOLS> & string)[]

          Limits the tools that are available for the model to call without changing the tool call and result types in the result.

        • Optionalexperimental_download?: DownloadFunction

          Custom download function to use for URLs.

          By default, files are downloaded if the model does not support the URL for the given media type.

        • Optionalexperimental_include?: GenerateTextInclude

          Settings for controlling what data is included in step results.

          Use include instead.

        • Optionalexperimental_onLanguageModelCallEnd?: OnLanguageModelCallEndCallback<NoInfer<TOOLS>>

          Callback that is called after the model response has been normalized and parsed, but before any client-side tool execution begins.

          Use onLanguageModelCallEnd instead.

        • Optionalexperimental_onLanguageModelCallStart?: OnLanguageModelCallStartCallback

          Callback that is called immediately before the provider model call begins.

          Use onLanguageModelCallStart instead.

        • Optionalexperimental_onStart?: GenerateTextOnStartCallback<
              NoInfer<TOOLS>,
              NoInfer<RUNTIME_CONTEXT>,
              NoInfer<OUTPUT>,
          >

          Callback that is called when the generateText operation begins, before any LLM calls are made.

          Use onStart instead.

        • Optionalexperimental_onStepStart?: GenerateTextOnStepStartCallback<
              NoInfer<TOOLS>,
              NoInfer<RUNTIME_CONTEXT>,
              NoInfer<OUTPUT>,
          >

          Callback that is called when a step (LLM call) begins, before the provider is called.

          Use onStepStart instead.

        • Optionalexperimental_onToolCallFinish?: OnToolExecutionEndCallback<NoInfer<TOOLS>>

          Callback that is called right after a tool's execute function completes (or errors).

          Use onToolExecutionEnd instead.

        • Optionalexperimental_onToolCallStart?: OnToolExecutionStartCallback<NoInfer<TOOLS>>

          Callback that is called right before a tool's execute function runs.

          Use onToolExecutionStart instead.

        • Optionalexperimental_refineToolInput?: ToolInputRefinement<NoInfer<TOOLS>>

          Optional mapping of tool names to functions that refine parsed tool inputs.

          The refined input must have the same type shape as the tool input. Refined inputs are used for tool execution, outputs, callbacks, and telemetry.

        • Optionalexperimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>

          A function that attempts to repair a tool call that failed to parse.

          Use repairToolCall instead.

        • Optionalexperimental_sandbox?: SandboxSession

          The sandbox environment that is passed through to tool execution.

        • Optionalexperimental_telemetry?: TelemetryOptions<RUNTIME_CONTEXT, NoInfer<TOOLS>>

          Optional telemetry configuration.

          Use telemetry instead. This alias will be removed in a future major release.

        • Optionalexperimental_toolApprovalSecret?: string | Uint8Array<ArrayBufferLike>

          Secret for HMAC-signing tool approval requests. When set, the server signs each approval request at issuance and verifies the signature when the approval is replayed, preventing client-forged approvals.

        • Optionalexperimental_toolCallers?: Experimental_ToolCallers<NoInfer<TOOLS>>

          Configures which caller tools may invoke each tool.

        • Optionalinclude?: GenerateTextInclude

          Settings for controlling what data is included in step results. Disabling inclusion can help reduce memory usage when processing large payloads like images.

          By default, request bodies, request messages, and response bodies are excluded.

        • model: LanguageModel

          The language model to use.

        • OptionalonEnd?: GenerateTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>

          Callback that is called when all steps are finished and the response is complete.

        • OptionalonFinish?: GenerateTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>

          Callback that is called when all steps are finished and the response is complete.

          Use onEnd instead.

        • OptionalonLanguageModelCallEnd?: OnLanguageModelCallEndCallback<NoInfer<TOOLS>>

          Callback that is called after the model response has been normalized and parsed, but before any client-side tool execution begins.

        • OptionalonLanguageModelCallStart?: OnLanguageModelCallStartCallback

          Callback that is called immediately before the provider model call begins.

        • OptionalonStart?: GenerateTextOnStartCallback<
              NoInfer<TOOLS>,
              NoInfer<RUNTIME_CONTEXT>,
              NoInfer<OUTPUT>,
          >

          Callback that is called when the generateText operation begins, before any LLM calls are made.

        • OptionalonStepEnd?: GenerateTextOnStepEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>

          Callback that is called when each step (LLM call) ends, including intermediate steps.

        • OptionalonStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>

          Callback that is called when each step (LLM call) ends, including intermediate steps.

          Use onStepEnd instead.

        • OptionalonStepStart?: GenerateTextOnStepStartCallback<
              NoInfer<TOOLS>,
              NoInfer<RUNTIME_CONTEXT>,
              NoInfer<OUTPUT>,
          >

          Callback that is called when a step (LLM call) begins, before the provider is called.

        • OptionalonToolExecutionEnd?: OnToolExecutionEndCallback<NoInfer<TOOLS>>

          Callback that is called right after a tool's execute function completes (or errors).

        • OptionalonToolExecutionStart?: OnToolExecutionStartCallback<NoInfer<TOOLS>>

          Callback that is called right before a tool's execute function runs.

        • Optionaloutput?: OUTPUT

          Optional specification for parsing structured outputs from the LLM response.

        • OptionalprepareStep?: PrepareStepFunction<NoInfer<TOOLS>, RUNTIME_CONTEXT>

          Optional function that you can use to provide different settings for a step.

        • OptionalproviderOptions?: ProviderOptions

          Additional provider-specific options. They are passed through to the provider from the AI SDK and enable provider-specific functionality that can be fully encapsulated in the provider.

        • OptionalrepairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>

          A function that attempts to repair a tool call that failed to parse.

        • OptionalruntimeContext?: RUNTIME_CONTEXT

          Runtime context. Treat runtime context as immutable. If you need to mutate runtime context, update it in prepareStep.

        • OptionalstopWhen?: Arrayable<StopCondition<NoInfer<TOOLS>, RUNTIME_CONTEXT>>

          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.

          isStepCount(1)
          
        • Optionaltelemetry?: TelemetryOptions<RUNTIME_CONTEXT, NoInfer<TOOLS>>

          Optional telemetry configuration.

        • OptionaltoolApproval?: ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT>

          Optional tool approval configuration.

          This configuration takes precedence over tool-defined approval settings.

        • OptionaltoolChoice?: ToolChoice<NoInfer<TOOLS>>

          The tool choice strategy. Default: 'auto'.

        • OptionaltoolOrder?: readonly (NoInfer<keyof TOOLS> & string)[]

          Controls the order in which tools are sent to the provider.

          The list can be partial. Tools not listed in toolOrder are sent after the listed tools, sorted alphabetically. This can improve provider-side caching by keeping tool definitions in a stable order.

      Returns Promise<GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>>

      A result object that contains the generated text, the results of the tool calls, and additional information.