Thinking & Reasoning
Many models support thinking/reasoning capabilities where they show their internal thought process before generating a response. The library provides both a unified interface and provider-specific options.Checking Reasoning Support
Check if a model supports reasoning:Reasoning-Capable Models
Models that support reasoning across providers:- OpenAI: o1-preview, o1-mini, o3-mini, gpt-5-mini, gpt-5-nano, gpt-5.1-omni
- Anthropic: claude-sonnet-4-20250514
- Google: gemini-2.0-flash, gemini-2.5-flash, gemini-2.5-pro
- xAI: grok-code-fast-1, grok-beta, grok-vision-beta
- Groq: openai/gpt-oss-20b, openai/gpt-oss-40b
- Cerebras: gpt-oss-120b
- OpenRouter: Various models (e.g., z-ai/glm-4.5v)
Unified Interface (Recommended)
UsestreamSimple and completeSimple for automatic cross-provider compatibility:
Reasoning Levels
Five reasoning levels with automatic provider mapping:xhigh is only available on OpenAI models with extended reasoning. On other providers, it automatically maps to high.Custom Token Budgets
Override default token budgets for token-based providers:Provider-Specific Options
For fine-grained control, use provider-specific options:Streaming Thinking Content
Thinking content is delivered through dedicated events:Thinking with Tool Calling
Combine reasoning with tool calls:Cross-Provider Handoffs
Thinking blocks are preserved when switching providers:How Cross-Provider Thinking Works
- Same provider/API: Thinking blocks preserved as-is
- Different provider: Thinking blocks converted to text with
<thinking>tags - Tool calls: Preserved unchanged across all providers
- Text content: Always preserved unchanged
Redacted Thinking
Some providers may redact thinking content for safety:Complete Example
Full workflow with reasoning:Cost Considerations
Reasoning tokens are included in output token count:Provider Comparison
Best Practices
- Start with
medium: Balanced performance and cost - Use
highfor complex tasks: Math, coding, logical reasoning - Avoid
xhighunless necessary: Very expensive, only on OpenAI - Stream for UX: Show thinking in real-time for transparency
- Monitor costs: Reasoning can 5-10x your token usage
- Use unified API:
streamSimple/completeSimplefor portability
Next Steps
Streaming
Learn about streaming thinking events
Tools
Combine reasoning with tool calling