Quick Start
How It Works
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
max_tokens | u32 | provider default | Maximum output tokens per request |
max_context | u32 | provider default | Maximum context window size |
Common Patterns
Budget-Aware Loops
Stop processing when cumulative cost gets too high:Verbose Usage Reporting
Best Practices
Set max_tokens for predictable output
Set max_tokens for predictable output
Always set
max_tokens when you know the expected output length. For short answers use 200, for summaries 500–1000, for detailed analysis 2000+. This prevents runaway generation and unexpected costs.Monitor cumulative usage
Monitor cumulative usage
Call
agent.token_usage() after each request to track total spend. In loops or multi-turn conversations, check the running total and stop when approaching your budget.Respect context window limits
Respect context window limits
Set
max_context slightly below the model’s documented limit to leave headroom. Running at 100% of the context window can cause errors with some providers.Use verbose mode in development
Use verbose mode in development
Enable
.verbose(true) during development to see token counts logged automatically after each request. Disable in production to reduce noise.Related
Budget
Dollar-based spending limits
Context Management
Context window strategies

