Skip to main content

Common Error Symptoms

When you see error messages like this:
{
  "error": {
    "message": "Incorrect API key provided: sk-QqHvK***...",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
This usually means NOT that your API Key is wrong, but that the Base URL is misconfigured.
Most Common Mistake: Using APIYI’s Key but sending requests to OpenAI’s official endpoint https://api.openai.com

What is Base URL?

Base URL (Base URL / Request Address) is the target server address for API requests. Different API service providers use different Base URLs.

Base URL and API Key Must Match

Service ProviderBase URLAPI Key FormatMatch?
APIYIhttps://api.apiyi.comsk-xxxx......✅ Correct
OpenAI Officialhttps://api.openai.comsk-xxxx......✅ Correct
❌ APIYI Keyhttps://api.openai.comsk-xxxx......Wrong
❌ OpenAI Keyhttps://api.apiyi.comsk-xxxx......Wrong
Key Principle: Use the Base URL that matches your API Key provider.

Correct Configuration

Simply replace the OpenAI endpoint with APIYI’s, keep everything else unchanged:
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-apiyi-key",  # Get Key from APIYI dashboard
    base_url="https://api.apiyi.com/v1"  # Change to APIYI address
)

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

Method 2: Use Environment Variables

Set environment variables so you don’t need to specify Base URL in code:
export OPENAI_API_KEY="sk-your-apiyi-key"
export OPENAI_BASE_URL="https://api.apiyi.com/v1"

Supported Base URL Formats

APIYI supports three Base URL formats depending on your code:

Troubleshooting

Possible Causes:
  1. Multiple configuration points: Check if Base URL is set in config files, environment variables, code initialization, etc.
  2. Proxy or middleware: Some proxy tools may redirect requests
  3. Cache issues: Restart the program or clear cache and retry
  4. Typo: Verify apiyi is spelled correctly (not apiyii or apiyl)
Check in APIYI dashboard:
  1. Login to APIYI dashboard console.apiyi.com
  2. Go to “Tokens” page
  3. Check if Key status is “Enabled”
  4. Confirm account has sufficient balance
Most third-party tools have “Custom API” or “Self-hosted Server” options:
  • API Address / Base URL: https://api.apiyi.com/v1
  • API Key: Copy your Key from APIYI dashboard
  • Model Name: Refer to model list in APIYI documentation
Configuration options are usually found in “Settings” → “API” or “Server” sections
APIYI provides complete code examples in multiple languages:
  1. Quick Start Documentation: Homepage → Code Examples
  2. Online Testing Tool: Dashboard → ApiFox Online Testing
  3. GitHub Repository: github.com/apiyi/docs → knowledge-base directory

Wrong vs Correct Examples

❌ Wrong Configuration

client = OpenAI(
    api_key="sk-apiyi-key",
    base_url="https://api.openai.com/v1"
    # ❌ Using OpenAI official endpoint
)
Result: OpenAI server will reject APIYI’s Key

✅ Correct Configuration

client = OpenAI(
    api_key="sk-apiyi-key",
    base_url="https://api.apiyi.com/v1"
    # ✅ Using APIYI endpoint
)
Result: Request successfully sent to APIYI server

Quick Test Method

Use cURL command to quickly verify your configuration:
curl https://api.apiyi.com/v1/models \
  -H "Authorization: Bearer sk-your-apiyi-key"
Expected Result: Returns list of available models
{
  "data": [
    {
      "id": "gpt-4o",
      "object": "model",
      ...
    }
  ]
}
If you get an error, check:
  1. API Key copied correctly (watch for leading/trailing spaces)
  2. Network connection is working
  3. Account has sufficient balance
Remember the core principle: Match the URL to the Key provider. APIYI’s Key uses https://api.apiyi.com/v1