# Access Hundreds of LLMs via OpenRouter

[OpenRouter](https://openrouter.ai/) provides a unified OpenAI-compatible API that gives access to 200+ models from multiple providers. This guide shows how to route traffic to OpenRouter through API7 Gateway using the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* Install [Docker](https://docs.docker.com/get-docker/).

* Install [cURL](https://curl.se/) to send requests to the services for validation.

* Have a running API7 Gateway instance.

* Create a [token from the Dashboard](https://docs.api7.ai/api7-gateway/reference/obtain-dashboard-token.md) and save it to an environment variable:

  ```
  export API_KEY=your-dashboard-token   # replace with your Dashboard token
  ```

* Replace `{gateway_group_id}` with your gateway group ID. Use `default` if you are following the quickstart.

* If you are following the Admin API examples, create or reuse a service in API7 Gateway. If you do not have one yet, follow [Create or Reuse a Service](https://docs.api7.ai/api7-gateway/ai-gateway/get-started.md#create-or-reuse-a-service), then save its ID to an environment variable:

  ```
  export SERVICE_ID=your-service-id         # replace with your service ID
  ```

## Obtain an OpenRouter API Key[​](#obtain-an-openrouter-api-key "Direct link to Obtain an OpenRouter API Key")

Create an account at [openrouter.ai](https://openrouter.ai/) and generate an API key. Save the key to an environment variable:

```
export OPENROUTER_API_KEY=sk-or-xxxxxxxxxxxxxxxxxxxxxxxx   # replace with your OpenRouter API key
```

## Configure the AI Proxy for OpenRouter[​](#configure-the-ai-proxy-for-openrouter "Direct link to Configure the AI Proxy for OpenRouter")

Create a route with the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin:

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/routes/openrouter-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d @- <<EOF

  {

    "name": "openrouter-route",

    "service_id": "$SERVICE_ID",

    "paths": ["/openrouter"],

    "plugins": {

      "ai-proxy": {

        "provider": "openrouter",

        "auth": {

          "header": {

            "Authorization": "Bearer $OPENROUTER_API_KEY"

          }

        },

        "options": {

          "model": "anthropic/claude-sonnet-5.5"

        }

      }

    }

  }

EOF
```

❶ Set the provider to `openrouter`.

❷ Attach the OpenRouter API key in the `Authorization` header.

❸ Set the model using the `provider/model` format. Browse available models at [openrouter.ai/models](https://openrouter.ai/models).

adc.yaml

```
services:

  - name: OpenRouter Service

    routes:

      - uris:

          - /openrouter

        name: openrouter-route

        plugins:

          ai-proxy:

            provider: openrouter

            auth:

              header:

                Authorization: "Bearer ${OPENROUTER_API_KEY}"

            options:

              model: anthropic/claude-sonnet-5.5

    labels:

      docs-example: openrouter-service
```

❶ Set the provider to `openrouter`.

❷ Attach the OpenRouter API key in the `Authorization` header.

❸ Set the model using the `provider/model` format. Browse available models at [openrouter.ai/models](https://openrouter.ai/models).

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=openrouter-service
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=openrouter-service
```

## Multi-Model Routing via OpenRouter[​](#multi-model-routing-via-openrouter "Direct link to Multi-Model Routing via OpenRouter")

Use [`ai-proxy-multi`](https://docs.api7.ai/hub/ai-proxy-multi.md) to load-balance across different models available through OpenRouter:

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/routes/openrouter-multi-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d @- <<EOF

  {

    "service_id": "$SERVICE_ID",

    "name": "openrouter-multi-route",

    "paths": ["/openrouter-multi"],

    "plugins": {

      "ai-proxy-multi": {

        "instances": [

          {

            "name": "budget-model",

            "provider": "openrouter",

            "auth": { "header": { "Authorization": "Bearer $OPENROUTER_API_KEY" } },

            "options": { "model": "google/gemini-3.6-flash" },

            "weight": 8

          },

          {

            "name": "premium-model",

            "provider": "openrouter",

            "auth": { "header": { "Authorization": "Bearer $OPENROUTER_API_KEY" } },

            "options": { "model": "anthropic/claude-sonnet-5.5" },

            "weight": 2

          }

        ]

      }

    }

  }

EOF
```

❶ Route 80% of traffic to a budget-friendly model.

❷ Route 20% to a premium model for higher-quality responses.

adc.yaml

```
services:

  - name: OpenRouter Multi-Model

    routes:

      - uris:

          - /openrouter-multi

        name: openrouter-multi-route

        plugins:

          ai-proxy-multi:

            instances:

              - name: budget-model

                provider: openrouter

                auth:

                  header:

                    Authorization: "Bearer ${OPENROUTER_API_KEY}"

                options:

                  model: google/gemini-3.6-flash

                weight: 8

              - name: premium-model

                provider: openrouter

                auth:

                  header:

                    Authorization: "Bearer ${OPENROUTER_API_KEY}"

                options:

                  model: anthropic/claude-sonnet-5.5

                weight: 2

    labels:

      docs-example: openrouter-multi-model
```

❶ Route 80% of traffic to a budget-friendly model.

❷ Route 20% to a premium model for higher-quality responses.

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=openrouter-multi-model
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=openrouter-multi-model
```

For more routing strategies, see [Multi-LLM Routing and Fallback](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/multi-llm-routing-and-fallback.md).

## Validate the Configuration[​](#validate-the-configuration "Direct link to Validate the Configuration")

Send this request to the multi-model route. To test the single-model route, use `/openrouter` instead of `/openrouter-multi`.

```
curl "http://127.0.0.1:9080/openrouter-multi" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "user", "content": "What is an API gateway?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  "id": "chatcmpl-abc123",

  "object": "chat.completion",

  "model": "anthropic/claude-sonnet-5.5",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "An API gateway is a server that acts as a single entry point for a set of microservices or APIs, handling request routing, composition, and protocol translation."

      },

      "finish_reason": "stop"

    }

  ],

  "usage": {

    "prompt_tokens": 10,

    "completion_tokens": 32,

    "total_tokens": 42

  }

}
```

To enable streaming responses, set `"stream": true` in the request body. Use the [`proxy-buffering`](https://docs.api7.ai/hub/proxy-buffering.md) plugin to disable NGINX `proxy_buffering` to avoid server-sent events (SSE) being buffered.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have learned how to route traffic to OpenRouter through API7 Gateway. See the [OpenRouter documentation](https://openrouter.ai/docs) to learn more about available models and pricing.

* [Multi-LLM Routing and Fallback](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/multi-llm-routing-and-fallback.md) — Combine OpenRouter with direct provider connections for failover.
* [Token Rate Limiting](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/token-rate-limiting-and-quota-management.md) — Control spending across models.
