> ## Documentation Index
> Fetch the complete documentation index at: https://ag2dev.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Compatible APIs

> A standardized API specification for LLM providers

## 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.

<Warning>
  **Never hardcode API keys in your code.** Always use environment variables or a secure secrets manager to store credentials.
</Warning>

### How It Works

| Configuration  | Description                                               |
| -------------- | --------------------------------------------------------- |
| **Base URL**   | The provider's API endpoint (instead of OpenAI's servers) |
| **API Key**    | Your authentication credential from the provider          |
| **Model Name** | The specific model identifier for that provider           |

<Info>
  All compatible providers support the standard OpenAI SDK. Install it with:
</Info>

```bash theme={null} theme={null}
pip install openai
# or
npm install openai
```

### Recommended Configuration

Use environment variables to configure your API client:

```bash theme={null} theme={null}
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:

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url=os.environ["OPENAI_COMPATIBLE_BASE_URL"],
      api_key=os.environ["OPENAI_COMPATIBLE_API_KEY"],
  )
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: process.env.OPENAI_COMPATIBLE_BASE_URL,
    apiKey: process.env.OPENAI_COMPATIBLE_API_KEY,
  });
  ```
</CodeGroup>

See individual provider pages for specific configuration details.
