Skip to main content
The generate_text function is the primary way to generate text using ai-query. It supports simple prompts, multi-turn conversations, tool calling, and automatic execution loops.

Basic Usage

Parameters

Using Messages

For multi-turn conversations, use the messages parameter:

System Prompts

Set the AI’s behavior with a system prompt:

Response Object

The generate_text function returns a GenerateTextResult:

Provider Options

Pass provider-specific options:

Reasoning

Use the top-level reasoning parameter for normalized reasoning-depth controls:
Current first-pass support:
  • OpenAI and OpenAI-compatible providers: effort
  • Google: budget
  • Anthropic: model-aware effort and budget
If you need provider-specific thinking visibility or raw provider configuration, continue using provider_options. If you want provider thinking output during streaming, see Thinking. generate_text() controls reasoning depth, but thinking output itself is exposed through stream_text(..., on_reasoning_event=...).

Error Handling

Next Steps

Streaming

Stream responses in real-time

Tools

Add tool calling capabilities