pip install -r requirements.txt- Go to https://openrouter.ai
- Sign up for an account
- Navigate to Keys
- Create a new API key
- Add some credits (minimum $1)
# Copy the example environment file
cp .env.example .env
# Edit .env and add your key
nano .env # or use your preferred editorYour .env should look like:
OPENROUTER_API_KEY=sk-or-v1-...your-key-here...
OPENROUTER_MODEL=anthropic/claude-3.5-sonnetpython validate_setup.pyIf you see "✓ All checks passed!" you're ready to go!
python examples/simple_example.pyEdit your .env file to try different models:
# For fast responses
OPENROUTER_MODEL=anthropic/claude-3-haiku
# For best quality
OPENROUTER_MODEL=anthropic/claude-3-opus
# For OpenAI
OPENROUTER_MODEL=openai/gpt-4-turbo
# For Google
OPENROUTER_MODEL=google/gemini-proSee all available models: https://openrouter.ai/models
# Custom tools
python examples/custom_tools_example.py
# Advanced multi-tool usage
python examples/advanced_example.pyCreate a new Python file:
from miniagent import MiniAgent, register_tool
import os
from dotenv import load_dotenv
load_dotenv()
# Define your custom tool
@register_tool
def my_tool(input_text: str) -> str:
"""Description of what your tool does"""
return f"Processed: {input_text}"
# Create agent
agent = MiniAgent(
model=os.getenv("OPENROUTER_MODEL"),
api_key=os.getenv("OPENROUTER_API_KEY")
)
# Add tools
from miniagent import get_tool_description
agent.tools.append(get_tool_description(my_tool))
agent.load_builtin_tool("calculator")
# Run!
response = agent.run("Your question here")
print(response)Problem: Invalid API key
Solution:
- Check your
.envfile - Make sure you copied the full key
- Verify key is active at https://openrouter.ai/keys
Problem: No credits in account
Solution: Add credits at https://openrouter.ai/credits
Problem: Dependencies not installed
Solution: Run pip install -r requirements.txt
Problem: Tools not loaded or model doesn't support them
Solution:
- Make sure you call
agent.load_builtin_tool()or add toagent.tools - Try a more capable model like Claude or GPT-4
Start with cheaper models for development:
anthropic/claude-3-haiku- Very fast, very cheapopenai/gpt-3.5-turbo- Good balance
Use expensive models only when needed:
anthropic/claude-3-opus- Most capableopenai/gpt-4-turbo- Very capable
Enable verbose logging:
import logging
logging.basicConfig(level=logging.DEBUG)Add delays between requests:
import time
response1 = agent.run("Query 1")
time.sleep(1) # Wait 1 second
response2 = agent.run("Query 2")- OpenRouter Docs: https://openrouter.ai/docs
- Model Comparison: https://openrouter.ai/models
- Pricing: https://openrouter.ai/docs/pricing
- Check the main README.md
- Run
python validate_setup.pyto diagnose issues - Review examples in
examples/directory - Open an issue on GitHub
Happy building! 🚀