Using Your Own OpenRouter Key
Take control of your AI model usage and billing by using your own OpenRouter API key
Benefits: Full control over costs, usage tracking, and rate limits. No additional charges from anytool for AI model usage.
Quick Setup
Add your OpenRouter API key as an environment variable:
OPENROUTER_APIKEY=sk-or-your-key-hereStep-by-Step Guide
1. Get Your OpenRouter API Key
Get your API key from OpenRouter (recommended for better rates and multiple model access):
- OpenRouter: openrouter.ai/keys (recommended)
- OpenAI: platform.openai.com/api-keys (direct)
2. Add to Environment Variables
- Go to Settings → Environment
- Add your key in the format:
OPENROUTER_APIKEY=sk-or-your-key-here - Save the variable
3. Verify Setup
Once added, you'll see a blue notification in your environment settings confirming that anytool will use your OpenRouter key.
How It Works
When Your Key Is Used
Your OPENROUTER_APIKEY is used for tool generation only—creating the tool code.
Important: Your key is NOT used for tool execution (running tools). Tool execution uses anytool's compute infrastructure and is included in your plan.
Tool Generation
When you generate a new tool:
- anytool checks for your
OPENROUTER_APIKEY - If found, uses your key for AI generation (~$0.30-0.50 per tool)
- If not found, uses anytool's key (fallback, only on Free tier)
Cost: Each tool generation costs ~$0.30-0.50, billed directly to your OpenRouter account.
Tool Execution
When your tools run:
- Your
OPENROUTER_APIKEYis injected into the execution environment - Generated tools can access it as
env.OPENROUTER_APIKEY - If your tool makes AI API calls, it can use your key (you control this)
- Tool execution itself (running the code) uses anytool's compute—no additional AI costs
Cost: Tool execution is included in your plan. Only if your generated tool makes its own AI API calls will those be billed to your OpenRouter account.
Billing & Usage
What You Pay
- Tool Generation: ~$0.30-0.50 per tool, billed directly to your OpenRouter account
- Tool Execution: Included in your anytool plan (no additional AI costs)
- AI Calls Within Tools: If your generated tool makes AI API calls, those are billed to your OpenRouter account
- anytool Subscription: Your monthly plan fee (Free or Pro $49/mo)
Example: Generate 100 tools/month = ~$30-50 to OpenRouter + $49 to anytool (Pro plan). Running those tools 10,000 times = $0 additional (included in plan).
Usage Tracking
Monitor your usage in:
- OpenRouter Dashboard: openrouter.ai/activity (recommended)
- OpenAI Dashboard: platform.openai.com/usage (if using direct OpenAI)
Code Examples
Using Your Key in Generated Tools
Your generated tools can access the key like this:
export default {
async fetch(request, env, ctx) {
// Your OpenRouter key is available as env.OPENROUTER_APIKEY
const openrouterKey = env.OPENROUTER_APIKEY;
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${openrouterKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'openai/gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello!' }]
})
});
return response;
}
};Best Practices
Security
- Never share your key: Keep it private and secure
- Use environment variables: Never hardcode keys in your tools
- Monitor usage: Set up alerts for unusual activity
Cost Optimization
- Use OpenRouter: Access to multiple models at competitive rates
- Set usage limits: Configure spending limits in your provider
- Monitor regularly: Check usage patterns and optimize
Rate Limits
- Your limits: Subject to your OpenRouter/OpenAI plan limits
- anytool limits: Still applies (100 requests/minute per API key)
- Combined effect: Most restrictive limit applies
Troubleshooting
Key Not Working
If your key isn't being used:
- Verify the key format:
sk-or-...for OpenRouter - Check it's saved as
OPENROUTER_APIKEY(exact spelling) - Ensure the key has sufficient credits/permissions
Unexpected Billing
If you're still being charged by anytool:
- Check your environment variables are saved correctly
- Verify the key is active and has credits
- Contact support if the issue persists
Rate Limit Errors
If you hit rate limits:
- Check your OpenRouter/OpenAI usage limits
- Consider upgrading your plan
- Reduce concurrent requests
Migration from anytool Key
To switch from anytool's key to your own:
- Add your
OPENROUTER_APIKEYto environment variables - Test with a simple tool generation
- Monitor your OpenRouter/OpenAI dashboard for usage
- Once confirmed, you're fully migrated
Next Steps
Ready to set up your own key?