Quick Start Guide
Get started with LLMGovernor in under 5 minutes. This guide will walk you through setting up cost tracking for your AI agents.
Prerequisites
- Python 3.8 or higher
- An active AI agent project using OpenAI, Anthropic, or other supported providers
- A LLMGovernor account (sign up at dashboard.Vivekreddy99.com)
Installation
Install the LLMGovernor Python SDK using pip:
pip install llmgovernor
Configuration
Get your API key from the LLMGovernor dashboard
Set your environment variable:
export LLMGOVERNOR_API_KEY="your-api-key-here"
Or add it to your .env file:
LLMGOVERNOR_API_KEY=your-api-key-here
Basic Usage
Add the @fleet.agent decorator to any function that makes LLM API calls:
import openai
from blaze_agents import fleet
# Set your OpenAI API key
openai.api_key = "your-openai-key"
@fleet.agent(budget=50.00) # Set $50 budget
def my_research_agent(query: str):
"""Research agent with cost tracking."""
response = openai.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful research assistant."},
{"role": "user", "content": query}
],
max_tokens=500
)
return response.choices[0].message.content
# Use your agent
result = my_research_agent("What are the latest developments in AI safety?")
print(result)
Advanced Configuration
Per-User Budgets
Track costs per user or session:
@fleet.agent(budget=25.00, user_id="user_123")
def personalized_agent(user_input: str, user_id: str):
# Agent logic here
pass
Custom Tags
Add custom tags for better cost categorization:
@fleet.agent(
budget=100.00,
tags={"department": "marketing", "campaign": "q4_2024"}
)
def marketing_agent(content: str):
# Agent logic here
pass
Budget Enforcement
When a budget is exceeded, LLMGovernor will raise a BudgetExceededError:
from blaze_agents.exceptions import BudgetExceededError
try:
result = my_research_agent("Complex query requiring many tokens")
except BudgetExceededError as e:
print(f"Budget exceeded: {e}")
# Handle gracefully - perhaps use a cheaper model
result = fallback_agent("Simplified query")
Monitoring
Visit your LLMGovernor dashboard to:
- View real-time cost tracking
- Set up alerts and notifications
- Analyze spending patterns
- Configure budget rules
Multi-Provider Support
LLMGovernor automatically detects and tracks costs for:
- OpenAI (GPT-3.5, GPT-4, etc.)
- Anthropic (Claude models)
- Google (PaLM, Gemini)
- Azure OpenAI
- Cohere
- Hugging Face
No additional configuration needed - just use the decorator!
Next Steps
- Check out the SDK Reference for advanced features
- Explore the API Documentation for custom integrations
- Join our Discord community for support
Need Help?
- 📚 Browse our documentation
- 💬 Join our Discord community
- 📧 Email us at [email protected]
- 🐛 Report issues on GitHub
Ready to track your AI costs? Sign up for free and get 100 events per month at no cost.