Skip to main content

Common Error

If you encounter an error message like the one below, it typically indicates an incorrect Base URL configuration.
{
  "error": {
    "message": "Incorrect API key provided: sk-QqHvK***...",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
Most common mistake: Using MixRoute API 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.

MixRoute’s Base URL and API Key Must Match

client = OpenAI(
    api_key="sk-mixroute-key",
    base_url="https://api.mixroute.ai/v1"
    # ✅ Using MixRoute Base URL
)

Correct Configuration

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-mixroute-key",  # Key from Mixroute Api console
    base_url="https://api.mixroute.ai/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://api.mixroute.ai/v1"

Supported URL Formats

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

Quick Test

Verify configuration with cURL:
curl https://api.mixroute.ai/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

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://api.mixroute.ai/v1
  • API Key: Copy from Mixroute Api console
  • Model name: Refer to model list