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

# OpenRouter

Move your existing OpenRouter integration to NexLLM by updating your API endpoint, credentials, and model identifiers.

NexLLM supports OpenAI-compatible Chat Completions, so you can keep your existing OpenAI SDK and standard message format.

<Tabs>
  <Tab title="Python (OpenAI SDK)">
    ```python theme={null}
    import os
    from openai import OpenAI

    # Before: OpenRouter
    openrouter_client = OpenAI(
        base_url="https://openrouter.ai/api/v1",
        api_key=os.environ["OPENROUTER_API_KEY"],
    )

    # After: NexLLM
    nexllm_client = OpenAI(
        base_url="https://www.nexllm.ai/v1",
        api_key=os.environ["NEXLLM_API_KEY"],
    )
    ```
  </Tab>

  <Tab title="JavaScript (OpenAI SDK)">
    ```javascript theme={null}
    import OpenAI from "openai";

    // Before: OpenRouter
    const openrouterClient = new OpenAI({
      baseURL: "https://openrouter.ai/api/v1",
      apiKey: process.env.OPENROUTER_API_KEY,
    });

    // After: NexLLM
    const nexllmClient = new OpenAI({
      baseURL: "https://www.nexllm.ai/v1",
      apiKey: process.env.NEXLLM_API_KEY,
    });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    # Before: OpenRouter
    curl https://openrouter.ai/api/v1/chat/completions \
      -H "Authorization: Bearer $OPENROUTER_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "openai/gpt-4o",
        "messages": [
          {"role": "user", "content": "Say hello in one word"}
        ]
      }'

    # After: NexLLM
    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": "Say hello in one word"}
        ]
      }'
    ```
  </Tab>
</Tabs>

<Note>
  The examples use documented NexLLM model identifiers. Before sending a request, confirm that the selected model is available to your API key through the Models endpoint.
</Note>

## Prerequisites

<Steps>
  <Step title="A NexLLM account with an active API key">
    Sign in to the [NexLLM dashboard](https://www.nexllm.ai/) and create an API key.

    Review the key's channel group, model restrictions, expiration, quota, and IP allowlist.

    See [API Keys](/get-started/getting-your-api-keys) for setup instructions.
  </Step>

  <Step title="Available account balance">
    Check your account balance before testing billable requests.

    See [Wallet](/account/wallet-and-top-up) for funding instructions.
  </Step>

  <Step title="An existing OpenRouter integration">
    This guide is for applications already using OpenRouter through the OpenAI SDK or an HTTP client.

    If you are starting a new integration, follow the [Quickstart](/get-started/quickstart) instead.
  </Step>
</Steps>

## Quick Start for Claude Code Users

If you use Claude Code to edit your application, give it the following migration instructions.

This is a prompt for updating your project, not a downloadable skill or a command that changes Claude Code's own model provider.

```text theme={null}
Migrate this application's OpenRouter integration to NexLLM.

Use these documentation pages:
- https://docs.nexllm.ai/get-started/quickstart
- https://docs.nexllm.ai/api-reference/authentication
- https://docs.nexllm.ai/api-reference/chat-completions
- https://docs.nexllm.ai/api-reference/models
- https://docs.nexllm.ai/channel-groups/overview

Requirements:
1. Find all OpenRouter client initialization, environment variables,
   model identifiers, headers, and provider-specific request fields.
2. Change the OpenAI SDK base URL to:
   https://www.nexllm.ai/v1
3. Read the NexLLM credential from NEXLLM_API_KEY.
   Never hard-code, print, or commit credentials.
4. Preserve standard Chat Completions messages and application behavior.
5. Map model identifiers explicitly using NexLLM documentation.
   Do not assume every OpenRouter prefix can simply be removed.
6. Create a verification script that lists models using GET /v1/models
   and sends one minimal Chat Completions request.
7. Remove OpenRouter attribution headers from the NexLLM client.
8. Flag provider routing, fallbacks, auto-routing, plugins, and privacy
   controls that need an explicit replacement. Do not silently discard
   required behavior or invent NexLLM equivalents.
9. Update environment examples and relevant tests.
10. Summarize the changes and any remaining compatibility gaps.

Ask before making live API calls or changing production configuration.
```

Review the proposed changes before applying them.

## Step 1: Update Your Environment Variables

Replace your OpenRouter configuration with NexLLM credentials and connection settings.

```bash theme={null}
# Before: OpenRouter
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
export OPENROUTER_BASE_URL="https://openrouter.ai/api/v1"
export OPENROUTER_MODEL="openai/gpt-4o"

# After: NexLLM
export NEXLLM_API_KEY="YOUR_NEXLLM_API_KEY"
export NEXLLM_BASE_URL="https://www.nexllm.ai/v1"
export NEXLLM_MODEL="gpt-4o"
```

The examples below use these application environment variables.

<Warning>
  Use a NexLLM-issued API key. Your OpenRouter credential is not a replacement for a NexLLM credential.

  Keep real keys in your server-side environment or secret manager. Never commit them or expose them in browser code.
</Warning>

## Step 2: Update Your Client

Configure your client with the NexLLM base URL and API key.

<Tabs>
  <Tab title="Python (OpenAI SDK)">
    ```python theme={null}
    import os
    from openai import OpenAI

    client = OpenAI(
        base_url=os.environ["NEXLLM_BASE_URL"],
        api_key=os.environ["NEXLLM_API_KEY"],
    )

    response = client.chat.completions.create(
        model=os.environ["NEXLLM_MODEL"],
        messages=[
            {
                "role": "user",
                "content": "Say hello in one word",
            }
        ],
    )

    print(response.choices[0].message.content)
    ```
  </Tab>

  <Tab title="JavaScript (OpenAI SDK)">
    ```javascript theme={null}
    import OpenAI from "openai";

    const client = new OpenAI({
      baseURL: process.env.NEXLLM_BASE_URL,
      apiKey: process.env.NEXLLM_API_KEY,
    });

    const response = await client.chat.completions.create({
      model: process.env.NEXLLM_MODEL,
      messages: [
        {
          role: "user",
          content: "Say hello in one word",
        },
      ],
    });

    console.log(response.choices[0]?.message?.content);
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "${NEXLLM_BASE_URL}/chat/completions" \
      -H "Authorization: Bearer $NEXLLM_API_KEY" \
      -H "Content-Type: application/json" \
      -d "{
        \"model\": \"${NEXLLM_MODEL}\",
        \"messages\": [
          {\"role\": \"user\", \"content\": \"Say hello in one word\"}
        ]
      }"
    ```
  </Tab>
</Tabs>

For endpoint details, see [Chat Completions](/api-reference/chat-completions).

### Remove OpenRouter Attribution Headers

Remove OpenRouter-specific attribution headers from the NexLLM client:

* `HTTP-Referer`
* `X-OpenRouter-Title`
* `X-Title`, if present in an older integration

Keep the authentication and content-type headers required by NexLLM.

See [Authentication](/api-reference/authentication).

### Review Routing and Other Extensions

Do not forward OpenRouter-specific options without checking their replacement behavior.

Review:

* The `provider` object and provider preferences.
* The `models` array used for model fallbacks.
* Automatic model selection.
* Plugins and request transformations.
* Provider-specific privacy or retention controls.

Start your compatibility test with a minimal request, then add required features individually.

<Warning>
  Channel groups are not a drop-in translation of OpenRouter's request-level routing options.

  If your application relies on provider restrictions, fallback rules, regional processing, or privacy requirements, verify those requirements before moving the affected workload.
</Warning>

## Step 3: Update Model Identifiers

Use the exact model IDs returned by NexLLM.

Examples documented by NexLLM include:

| Model | NexLLM model ID |
| - | - |
| GPT-4o | `gpt-4o` |
| Claude Haiku 4.5 through the documented AWS route | `aws/claude-haiku-4-5` |
| Gemini 2.5 Flash | `gemini-2.5-flash` |

For example, an OpenRouter request using `openai/gpt-4o` should use NexLLM's documented `gpt-4o` identifier, provided it is available to your key.

Do not apply a blanket rule that removes or replaces every prefix. Some NexLLM identifiers contain a prefix, as shown by `aws/claude-haiku-4-5`.

### List Models Available to Your Key

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

  <Tab title="Python">
    ```python theme={null}
    import os
    from openai import OpenAI

    client = OpenAI(
        base_url="https://www.nexllm.ai/v1",
        api_key=os.environ["NEXLLM_API_KEY"],
    )

    for model in client.models.list().data:
        print(model.id)
    ```
  </Tab>
</Tabs>

The returned catalog reflects your key's channel group. Copy the desired `id` exactly.

See the [Models API](/api-reference/models).

### Review Auto-Routing Separately

If your existing application uses `openrouter/auto`, do not automatically rename it to `auto`.

Select an explicit NexLLM model for initial testing, and verify any automatic selection requirements separately.

### Check Your Channel Group

Each NexLLM API key belongs to one channel group. That group determines model access and the pricing multiplier applied to usage.

Before deployment:

1. Check the group assigned to the production key.
2. Confirm that it includes the intended models.
3. Review its pricing and connectivity characteristics.
4. Verify any additional key-level model restrictions.

See [Channel Groups](/channel-groups/overview).

## Step 4 (Optional): Adopt the Responses API

You can keep using Chat Completions after migrating.

If your application needs the OpenAI Responses format, NexLLM also documents:

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

Before using this endpoint, check the selected model's API compatibility in Model Square. The examples below assume `NEXLLM_MODEL` is set to a model that supports Responses.

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl "${NEXLLM_BASE_URL}/responses" \
      -H "Authorization: Bearer $NEXLLM_API_KEY" \
      -H "Content-Type: application/json" \
      -d "{
        \"model\": \"${NEXLLM_MODEL}\",
        \"input\": \"What is the capital of France?\"
      }"
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import json
    import os
    from urllib.request import Request, urlopen

    url = os.environ["NEXLLM_BASE_URL"].rstrip("/") + "/responses"

    payload = {
        "model": os.environ["NEXLLM_MODEL"],
        "input": "What is the capital of France?",
    }

    request = Request(
        url,
        data=json.dumps(payload).encode("utf-8"),
        headers={
            "Authorization": f"Bearer {os.environ['NEXLLM_API_KEY']}",
            "Content-Type": "application/json",
        },
        method="POST",
    )

    with urlopen(request, timeout=60) as response:
        print(json.load(response))
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const baseURL = process.env.NEXLLM_BASE_URL.replace(/\/$/, "");

    const response = await fetch(`${baseURL}/responses`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.NEXLLM_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        model: process.env.NEXLLM_MODEL,
        input: "What is the capital of France?",
      }),
    });

    if (!response.ok) {
      throw new Error(`NexLLM request failed: HTTP ${response.status}`);
    }

    console.log(await response.json());
    ```
  </Tab>
</Tabs>

<Note>
  Responses uses a different request and response shape from Chat Completions. Update your response parsing and test the specific features your application requires rather than changing only the endpoint.
</Note>

See the [API Reference](/api-reference/overview) for supported endpoint formats.

## Why Migrate to NexLLM

### Keep Your OpenAI-Compatible Client

Use NexLLM's Chat Completions endpoint with your existing OpenAI SDK.

For a basic integration, the main changes are the base URL, credential, and model ID. Review provider-specific extensions separately.

### Access GPT, Claude, and Gemini

Use a single API integration for multiple model families, subject to your key's permissions and channel group.

Explore:

* [GPT Models](/models/gpt-series)
* [Claude Models](/models/claude-series)
* [Gemini Models](/models/gemini-series)

### Choose Model Access and Pricing Through Channel Groups

Select a channel group that matches your model requirements and preferred pricing.

The group ratio adjusts the model's base usage cost:

```text theme={null}
Final Cost = Base Model Cost × Group Ratio
```

Check current group availability and pricing before choosing a production configuration.

See [Channel Groups](/channel-groups/overview) and [Pricing](/channel-groups/pricing-overview).

### Configure Access Controls Per Key

Create separate keys for different projects or environments.

NexLLM documents configurable expiration, quota limits, model restrictions, and IP allowlists.

See [API Keys](/get-started/getting-your-api-keys).

### Review Requests and Usage

Use NexLLM's usage logs to inspect request timing, key names, models, token consumption, and cost.

The dashboard provides aggregate request, token, and quota statistics.

See [Usage & Logs](/account/usage-logs-and-statistics).

### Choose an API Format That Fits Your Application

Alongside Chat Completions, NexLLM documents Responses and Claude-native Messages endpoints.

Check endpoint compatibility for your chosen model before changing formats.

See the [API Reference](/api-reference/overview).

## Troubleshooting

<AccordionGroup>
  <Accordion title="Model not found or unavailable">
    Call `GET /v1/models` using the same API key as the failing application.

    Verify the exact model ID, the key's channel group, and any model restrictions configured on the key.

    Do not assume an OpenRouter identifier is accepted unchanged.

    See [Models](/api-reference/models).
  </Accordion>

  <Accordion title="Invalid API key or authentication failure">
    Confirm that `NEXLLM_API_KEY` contains your NexLLM credential, not the old OpenRouter key.

    Check for extra whitespace, stale deployment secrets, expiration, and IP allowlist restrictions.

    Standard OpenAI-compatible requests use:

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

    See [Authentication](/api-reference/authentication).
  </Accordion>

  <Accordion title="Connection errors or incorrect endpoint">
    Confirm that the SDK base URL is:

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

    Do not retain OpenRouter's `/api/v1` path or append `/v1` twice.

    Test authentication and connectivity with:

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

    A successful model-list request does not replace testing an actual completion request.
  </Accordion>

  <Accordion title="Insufficient balance or exhausted quota">
    Review your account balance and the quota configured for the API key.

    Check both before retrying the request.

    See [Wallet](/account/wallet-and-top-up) and [API Keys](/get-started/getting-your-api-keys).
  </Accordion>

  <Accordion title="An optional parameter or advanced feature fails">
    Reduce the request to a supported model and a short messages array.

    Reintroduce optional fields one at a time, checking the chosen model's endpoint compatibility.

    Pay particular attention to OpenRouter-specific routing fields, plugins, and fallback settings.

    Test streaming, tools, structured outputs, and multimodal inputs separately if your application uses them.
  </Accordion>

  <Accordion title="Usage or costs differ from the previous integration">
    Check the requested model, actual token usage, and the pricing ratio for your key's channel group.

    Review any applicable cache or multimodal charges.

    Use NexLLM's pricing information rather than carrying over OpenRouter-specific accounting assumptions.

    See [Pricing](/channel-groups/pricing-overview) and [Usage & Logs](/account/usage-logs-and-statistics).
  </Accordion>
</AccordionGroup>

## Verify Before Production

Use this checklist before completing the migration:

* [ ] Replace the base URL and API key.
* [ ] Confirm model IDs using the production key.
* [ ] Review the key's channel group and restrictions.
* [ ] Remove OpenRouter attribution headers.
* [ ] Review routing, fallbacks, and provider-specific fields.
* [ ] Verify required privacy and retention controls.
* [ ] Test representative prompts and conversation history.
* [ ] Test streaming and other advanced features where used.
* [ ] Check error handling, timeouts, and retries.
* [ ] Review usage logs and expected costs.
* [ ] Keep a tested rollback configuration during rollout.

Start with staging, then move a small portion of production traffic before expanding the rollout.

Keep the old endpoint, credentials, model mapping, and request options together so rollback restores a consistent configuration.

## Next Steps

<CardGroup cols={2}>
  <Card title="API Reference" icon="code" href="/api-reference/overview">
    Explore supported endpoints and request formats.
  </Card>

  <Card title="Available Models" icon="list" href="/api-reference/models">
    Find exact model IDs available to your API key.
  </Card>

  <Card title="Channel Groups" icon="layer-group" href="/channel-groups/overview">
    Understand model access and group pricing.
  </Card>

  <Card title="Usage & Logs" icon="chart-line" href="/account/usage-logs-and-statistics">
    Inspect requests and monitor usage after migration.
  </Card>
</CardGroup>

## Feedback

When reporting a migration issue to the NexLLM team, include:

* Your SDK and version.
* The endpoint and model ID.
* The HTTP status and sanitized error message.
* The approximate request time.
* A request identifier, if available.
* A minimal reproduction with sensitive content removed.

Do not include API keys, authorization headers, private prompts, or sensitive historical logs.


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