Skip to main content

Overview

generate_text is a high-level helper for synchronous text generation that returns a GenerateTextResult with rich metadata including usage statistics, finish reasons, and tool calls.

Basic usage

generate_text.py

Parameters

Return value

GenerateTextResult exposes rich metadata:

Examples

Basic text generation

With system instruction

With custom parameters

Tool-calling

See the dedicated Tool page for a complete walkthrough.

generate_text is provider-agnostic. Swap openai() for anthropic() or any other future implementation – no code changes required.