Skip to main content

Common Error

When you see an error like this:
{
  "error": {
    "message": "Incorrect API key provided: sk-QqHvK***...",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
This usually isn’t a problem with your API Key itself, but rather a Base URL misconfiguration.
Most common mistake: Using Mixroute Api’s Key but the request URL still points to OpenAI’s https://api.openai.com

What is Base URL?

Base URL is the target server address for API requests. Different providers use different Base URLs.

Base URL and API Key Must Match

ProviderBase URLAPI Key FormatMatch?
Mixroute Apihttps://console.mixroute.iosk-xxxx…✅ Correct
OpenAI Officialhttps://api.openai.comsk-xxxx…✅ Correct
❌ Mixroute Keyhttps://api.openai.comsk-xxxx…❌ Wrong
❌ OpenAI Keyhttps://console.mixroute.iosk-xxxx…❌ Wrong
Key principle: Use the provider’s Base URL that matches your API Key

Correct Configuration

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-mixroute-key",  # Key from Mixroute Api console
    base_url="https://console.mixroute.io/v1"  # Use Mixroute Api URL
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}]
)

Method 2: Environment Variables

export OPENAI_API_KEY="sk-your-mixroute-key"
export OPENAI_BASE_URL="https://console.mixroute.io/v1"

Supported URL Formats

FormatURLUse Case
With /v1 (recommended)https://console.mixroute.io/v1Most libraries
With trailing slashhttps://console.mixroute.io/v1/Some frameworks
Full pathhttps://console.mixroute.io/v1/chat/completionscURL requests

Troubleshooting

Possible causes:
  1. Typos: Verify the URL spelling
  2. Cache issues: Restart program or clear cache
  3. Proxy or middleware: Some tools may redirect requests
  4. Multiple configurations: Check config files, env vars, code initialization
Check in Mixroute Api console:
  1. Login to Mixroute Api Console
  2. Go to “Tokens” page
  3. Check if Key status is “Enabled”
  4. Confirm account balance is sufficient
Most tools have “Custom API” options:
  • API URL / Base URL: https://console.mixroute.io/v1
  • API Key: Copy from Mixroute Api console
  • Model name: Refer to model list

Wrong vs Correct Examples

❌ Wrong Configuration

client = OpenAI(
    api_key="sk-mixroute-key",
    base_url="https://api.openai.com/v1"
    # ❌ Using OpenAI's URL
)
Result: OpenAI server rejects Mixroute Api’s Key

✅ Correct Configuration

client = OpenAI(
    api_key="sk-mixroute-key",
    base_url="https://console.mixroute.io/v1"
    # ✅ Using Mixroute Api URL
)
Result: Request successfully sent to Mixroute Api

Quick Test

Verify configuration with cURL:
curl https://console.mixroute.io/v1/models \
  -H "Authorization: Bearer sk-your-mixroute-key"
Expected result: Returns available models list
{
  "data": [
    {
      "id": "gpt-4o",
      "object": "model"
    }
  ]
}
If you get an error, check:
  1. API Key copied correctly (no extra spaces)
  2. Network connection is working
  3. Account balance is sufficient
Remember: Match the Key to its URL. Mixroute Api Key uses https://console.mixroute.io/v1