Guide

Migration Guide

Migrate to API Key Hub from OpenAI or Anthropic direct APIs with minimal code changes. Since API Key Hub is fully OpenAI-compatible, the migration is typically a one-line change.

Why Migrate to API Key Hub?

Multi-Provider Access

Access OpenAI, Anthropic, Google, Mistral, and more through a single API key.

Cost Savings

Competitive pricing with no monthly minimums. Pay only for what you use.

No Vendor Lock-In

Switch between models from different providers without changing your code.

Built-In Monitoring

Usage tracking, budget controls, and rate limiting out of the box.

Migrating from OpenAI Direct API

Since API Key Hub is fully OpenAI-compatible, migrating from OpenAI is the simplest possible change: just update the base URL and API key. Everything else in your code stays exactly the same.

Step 1: Update the Client Configuration

Python

BeforePython
from openai import OpenAI

client = OpenAI(
    api_key="sk-openai-key"
)

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

client = OpenAI(
    base_url="https://xylove.net/v1",
    api_key="sk-your-apikeyhub-key"
)

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

Node.js

BeforeNode.js
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-openai-key",
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
});
AfterNode.js
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://xylove.net/v1",
  apiKey: "sk-your-apikeyhub-key",
});

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

cURL

BeforecURL
curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer sk-openai-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello!"}]}'
AftercURL
curl https://xylove.net/v1/chat/completions \
  -H "Authorization: Bearer sk-your-apikeyhub-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello!"}]}'

Step 2: Update Environment Variables

If you use environment variables for configuration (recommended), update them:

BeforeShell (.env)
OPENAI_API_KEY=sk-openai-key
OPENAI_BASE_URL=https://api.openai.com/v1
AfterShell (.env)
OPENAI_API_KEY=sk-your-apikeyhub-key
OPENAI_BASE_URL=https://xylove.net/v1

Step 3: Try Different Models (Optional)

Now that you are on API Key Hub, you can access models from other providers without any code changes -- just change the model name:

Python
# Use Anthropic Claude
response = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Use Google Gemini
response = client.chat.completions.create(
    model="gemini-2.5-pro",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Use DeepSeek
response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Hello!"}]
)

What Stays the Same

  • Request and response format (100% OpenAI-compatible)
  • Streaming support (SSE format)
  • Function calling / tool use
  • JSON mode
  • Embeddings API
  • All SDK features (retries, timeouts, etc.)

Migration Checklist

  • Create an API Key Hub account and get your API key
  • Update your base URL to https://xylove.net/v1
  • Replace your provider API key with your API Key Hub key
  • If migrating from Anthropic, switch to the OpenAI SDK format
  • Update environment variables in all environments (dev, staging, prod)
  • Test with the API Playground to verify everything works
  • Set up budget alerts and rate limits in your Dashboard

Need Help?

If you run into issues during migration, check the Error Codes page for troubleshooting, or refer to the API Reference for detailed endpoint documentation.