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 themessages parameter:
System Prompts
Set the AI’s behavior with a system prompt:Response Object
Thegenerate_text function returns a GenerateTextResult:
Provider Options
Pass provider-specific options:Reasoning
Use the top-levelreasoning parameter for normalized reasoning-depth controls:
- OpenAI and OpenAI-compatible providers:
effort - Google:
budget - Anthropic: model-aware
effortandbudget
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