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-here

Step-by-Step Guide

1. Get Your OpenRouter API Key

Get your API key from OpenRouter (recommended for better rates and multiple model access):

2. Add to Environment Variables

  1. Go to Settings → Environment
  2. Add your key in the format: OPENROUTER_APIKEY=sk-or-your-key-here
  3. 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:

  1. anytool checks for your OPENROUTER_APIKEY
  2. If found, uses your key for AI generation (~$0.30-0.50 per tool)
  3. 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:

  1. Your OPENROUTER_APIKEY is injected into the execution environment
  2. Generated tools can access it as env.OPENROUTER_APIKEY
  3. If your tool makes AI API calls, it can use your key (you control this)
  4. 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:

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:

  1. Verify the key format: sk-or-... for OpenRouter
  2. Check it's saved as OPENROUTER_APIKEY (exact spelling)
  3. Ensure the key has sufficient credits/permissions

Unexpected Billing

If you're still being charged by anytool:

  1. Check your environment variables are saved correctly
  2. Verify the key is active and has credits
  3. 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:

  1. Add your OPENROUTER_APIKEY to environment variables
  2. Test with a simple tool generation
  3. Monitor your OpenRouter/OpenAI dashboard for usage
  4. Once confirmed, you're fully migrated

Next Steps

Ready to set up your own key?