Skip to main content

What are OpenAI Compatible APIs?

An OpenAI Compatible API is an API endpoint that implements the same specification as OpenAI’s API. This standardization allows developers to use multiple AI providers through a familiar interface without rewriting code.

Why It Matters

Instead of being locked into a single provider, you can switch between different LLM services by simply changing the API endpoint and credentials in your existing OpenAI client code.
Never hardcode API keys in your code. Always use environment variables or a secure secrets manager to store credentials.

How It Works

ConfigurationDescription
Base URLThe provider’s API endpoint (instead of OpenAI’s servers)
API KeyYour authentication credential from the provider
Model NameThe specific model identifier for that provider
All compatible providers support the standard OpenAI SDK. Install it with:
pip install openai
# or
npm install openai
Use environment variables to configure your API client:
export OPENAI_COMPATIBLE_BASE_URL="https://api.provider.com/v1"
export OPENAI_COMPATIBLE_API_KEY="your_api_key_here"
export OPENAI_COMPATIBLE_MODEL_NAME="provider-model-name"
Then use these in your code:
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["OPENAI_COMPATIBLE_BASE_URL"],
    api_key=os.environ["OPENAI_COMPATIBLE_API_KEY"],
)
See individual provider pages for specific configuration details.