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

# Compatible APIs

Point existing OpenAI-compatible (and selected native) clients at NexLLM. Change two values — **base URL** and **API key** — and keep the provider request format you already use. Spend lands on your [www.nexllm.ai](https://www.nexllm.ai) wallet.

## Introduction

NexLLM is an OpenAI-compatible AI gateway. The commercial path for apps, scripts, and IDE plugins is:

```text theme={null}
https://www.nexllm.ai/v1
```

Authentication for standard OpenAI-shaped requests:

```text theme={null}
Authorization: Bearer YOUR_NEXLLM_API_KEY
```

| Endpoint | Format | When to use |
| - | - | - |
| `POST /v1/chat/completions` | OpenAI Chat Completions | Default for chat / tools / streaming |
| `POST /v1/responses` | OpenAI Responses | When you need the Responses API shape |
| `POST /v1/completions` | Legacy text completions | Older prompt-only clients |
| `POST /v1/embeddings` | OpenAI embeddings | RAG / search |
| `POST /v1/images/generations` | OpenAI images | Text-to-image |
| `POST /v1/images/edits` | OpenAI image edits | Edit / inpaint style flows |
| `POST /v1/audio/transcriptions` | OpenAI STT | Speech-to-text |
| `POST /v1/audio/speech` | OpenAI TTS | Text-to-speech |
| `POST /v1/rerank` | Rerank | Document ranking |
| `GET /v1/models` | Models list | Discover IDs for your key |
| `POST /v1/messages` | Anthropic Messages | Native Claude request shape |
| `GET /v1/realtime` | Realtime (WebSocket) | Realtime sessions when enabled for your key |

Full field reference: [API Reference](https://docs.nexllm.ai/api-reference/overview.md). Agent-side tools instead of app code: [MCP integration](https://docs.nexllm.ai/integrations/mcp-integration.md).

> [!NOTE]
>
> Model IDs are whatever `GET /v1/models` returns for **your** API key (channel group + key restrictions). Examples in this page (`gpt-4o`, `aws/claude-haiku-4-5`) are illustrative — always confirm live IDs for your account.

## Prerequisites

* A NexLLM account and API key ([Getting your API keys](https://docs.nexllm.ai/get-started/getting-your-api-keys.md))
* Wallet balance for paid calls ([Wallet](https://docs.nexllm.ai/account/wallet-and-top-up.md))
* Any client that accepts a configurable OpenAI `base_url` / `baseURL`, or Anthropic `base_url` for Messages

## OpenAI Chat Completions

### Quick start (cURL)

```bash theme={null}
curl https://www.nexllm.ai/v1/chat/completions \
  -H "Authorization: Bearer $NEXLLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "user", "content": "Write a one-line product tagline."}
    ],
    "max_tokens": 100
  }'
```

### OpenAI Python SDK

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_NEXLLM_API_KEY",
    base_url="https://www.nexllm.ai/v1",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a one-line product tagline."}],
    max_tokens=100,
)

print(response.choices[0].message.content)
```

### OpenAI TypeScript / Node SDK

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

const client = new OpenAI({
  apiKey: process.env.NEXLLM_API_KEY,
  baseURL: "https://www.nexllm.ai/v1",
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Write a one-line product tagline." }],
  max_tokens: 100,
});

console.log(response.choices[0]?.message?.content);
```

### Streaming

Set `"stream": true` (or `stream: true` in the SDK). The SSE shape matches OpenAI Chat Completions (`choices[0].delta.content`, ending with `data: [DONE]`).

```python theme={null}
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Tell me a short joke."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)
```

## OpenAI Responses

Use when your stack targets `/v1/responses` instead of Chat Completions. Confirm the model’s `supported_endpoint_types` via `GET /v1/models` first.

```python theme={null}
response = client.responses.create(
    model="gpt-4o",
    input="Write a one-line product tagline.",
)
print(response.output_text)
```

See [API Reference](https://docs.nexllm.ai/api-reference/overview.md) and [Migrate from Vercel AI Gateway](https://docs.nexllm.ai/migrations/vercel-ai-gateway.md) for Responses notes with the Vercel AI SDK.

## Anthropic Messages (native)

NexLLM also accepts Anthropic’s Messages shape at `POST /v1/messages`. Pass your NexLLM key in `x-api-key` (and include `anthropic-version`), or use Bearer auth as documented in [Authentication](https://docs.nexllm.ai/api-reference/authentication.md).

```bash theme={null}
curl https://www.nexllm.ai/v1/messages \
  -H "x-api-key: $NEXLLM_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "aws/claude-haiku-4-5",
    "max_tokens": 100,
    "messages": [{"role": "user", "content": "Write a short welcome message."}]
  }'
```

## Images

```bash theme={null}
curl https://www.nexllm.ai/v1/images/generations \
  -H "Authorization: Bearer $NEXLLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dall-e-3",
    "prompt": "A product hero shot on a clean studio background",
    "n": 1,
    "size": "1024x1024"
  }'
```

Confirm an image-capable model ID with `GET /v1/models`. Details: [Image Generation API](https://docs.nexllm.ai/api-reference/image-generation.md).

For Vercel AI SDK apps, chat uses `@ai-sdk/openai` against this same base URL; images can use the OpenAI SDK/HTTP path or `@nexllm/ai-sdk-provider` — see [Vercel AI SDK](https://docs.nexllm.ai/integrations/vercel-ai).

## Discover models for your key

```bash theme={null}
curl https://www.nexllm.ai/v1/models \
  -H "Authorization: Bearer $NEXLLM_API_KEY"
```

Use the exact `data[].id` values in later calls. Channel groups and key restrictions change the catalog — see [Channel groups](https://docs.nexllm.ai/channel-groups/overview.md) and [Models API](https://docs.nexllm.ai/api-reference/models.md).

## Key differences vs calling OpenAI directly

| Aspect | OpenAI | NexLLM |
| - | - | - |
| Base URL | `https://api.openai.com/v1` | `https://www.nexllm.ai/v1` |
| API key | OpenAI key | NexLLM key (`Authorization: Bearer …`) |
| Model IDs | OpenAI catalog | Your channel-group catalog (GPT, Claude, Gemini, and more) |
| Billing | OpenAI account | NexLLM wallet |
| Request / response shape | OpenAI schema | Same OpenAI schema on compatible endpoints |

## When to use Compatible APIs vs MCP vs Skills

| Need | Use |
| - | - |
| App / backend / SDK code | **Compatible APIs** (this page) |
| Claude / Cursor / other agents with tools | [MCP integration](https://docs.nexllm.ai/integrations/mcp-integration.md) |
| Outcome recipes on top of MCP | [Skills](https://docs.nexllm.ai/integrations/skills.md) |
| Next.js / Vercel AI SDK chat | [Vercel AI SDK](https://docs.nexllm.ai/integrations/vercel-ai) |

## Billing

Compatible API calls use standard gateway rates for the model and endpoint. There is no separate “compatible API” surcharge. See [Pricing overview](https://docs.nexllm.ai/channel-groups/pricing-overview.md) and [Wallet](https://docs.nexllm.ai/account/wallet-and-top-up.md).

## Troubleshooting

> [accordion] 401 / authentication failed
>
> Confirm `Authorization: Bearer` uses a NexLLM key (not an OpenAI or Vercel gateway key). Check expiry, IP allowlist, and whitespace. See [Authentication](https://docs.nexllm.ai/api-reference/authentication.md).

> [accordion] Model not found
>
> Call `GET /v1/models` with the **same** key. Use the exact `id`. Check the key’s [channel group](https://docs.nexllm.ai/channel-groups/overview.md) and any model allowlist on the key.

> [accordion] Insufficient balance
>
> Top up the [wallet](https://docs.nexllm.ai/account/wallet-and-top-up.md) and retry. Usage logs are under [Usage](https://docs.nexllm.ai/account/usage-logs-and-statistics.md).

> [accordion] Wrong endpoint for this model
>
> Some models only support Chat Completions, Responses, or Messages. Inspect `supported_endpoint_types` on `GET /v1/models` before switching shapes.

## Related

* [Quickstart](https://docs.nexllm.ai/get-started/quickstart.md)
* [API Reference](https://docs.nexllm.ai/api-reference/overview.md)
* [Authentication](https://docs.nexllm.ai/api-reference/authentication.md)
* [MCP integration](https://docs.nexllm.ai/integrations/mcp-integration.md)
* [Skills](https://docs.nexllm.ai/integrations/skills.md)
* [Vercel AI SDK](https://docs.nexllm.ai/integrations/vercel-ai)
* [Migrate from OpenRouter](https://docs.nexllm.ai/migrations/openrouter.md) and other [migrations](https://docs.nexllm.ai/migrations-overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.