# OpenRouter compatibility

AIxAPI accepts OpenRouter's request format. Code written for OpenRouter keeps working after you change the base URL and the API key.

## Switch from OpenRouter

| | OpenRouter | AIxAPI |
|---|---|---|
| Base URL | `https://openrouter.ai/api/v1` | `https://www.aixapi.io/v1` |
| API key | `sk-or-...` | Create one in the console |
| Model name | `anthropic/claude-sonnet-4.6` | Same, or `claude-sonnet-4-6` (IDs from the [Model hub](https://www.aixapi.io/model-plaza)) |

```python
from openai import OpenAI

client = OpenAI(base_url="https://www.aixapi.io/v1", api_key="YOUR_AIXAPI_KEY")
client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={"provider": {"sort": "price"}},
)
```

The `provider` object works on `/v1/chat/completions`, `/v1/responses` and `/v1/messages`.

## Provider routing

Add a `provider` object to the request body. Field names and meanings follow OpenRouter.

| Field | Effect |
|---|---|
| `order` | Try these providers first, in this order |
| `only` | Use only these providers |
| `ignore` | Never use these providers |
| `allow_fallbacks` | `false`: stop after the providers in `order` fail. Default `true` |
| `sort` | `price`: cheapest first. `latency`: lowest time to first token first. `throughput`: fastest output first |

```bash
curl https://www.aixapi.io/v1/chat/completions \
  -H "Authorization: Bearer $AIXAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [{"role": "user", "content": "Hello"}],
    "provider": { "order": ["aixapi/claude-economy"], "allow_fallbacks": true }
  }'
```

**Provider names.** A provider is named by its slug, such as `aixapi`. A provider can offer one model through several groups at different prices, such as `aixapi/claude-economy`. A provider slug matches all of its groups; a group slug matches only that group. Each model's page in the [Model hub](https://www.aixapi.io/model-plaza) lists its providers, groups and prices.

## Model list

`GET /v1/models` without an API key returns every public model with its name, context length, modalities and lowest price in USD per token, like OpenRouter's model list. With an API key it returns the models that key can use.

## Key, credits and generation

| Endpoint | Returns |
|---|---|
| `GET /v1/key` | The API key's `label`, `limit`, `limit_remaining`, `usage`, `usage_daily` / `usage_weekly` / `usage_monthly` (UTC) and `is_free_tier` |
| `GET /v1/credits` | `total_credits` and `total_usage`; the difference is the current balance, bonus credit included |
| `GET /v1/generation?id=` | Cost, model, tokens, latency and provider of one request |

Responses use OpenRouter's `{"data": {...}}` shape and amounts are in USD. For `/v1/generation`, pass the `X-Client-Request-ID` response header of the request; a `gen-` prefix is accepted. Usage is recorded a few seconds after the response finishes.

## Model suffixes

| Suffix | Same as |
|---|---|
| `:floor` | `"sort": "price"` |
| `:nitro` | `"sort": "throughput"` |

`claude-sonnet-4-6:floor` routes to the cheapest provider for `claude-sonnet-4-6`.

## Defaults

- Without a `provider` object, a request follows the API key's routing preference (recommended, lowest price or most reliable), set in the console.
- Requests that carry the same session ID stay on the same provider, so prompt caching keeps working. An explicit `order` or `sort` overrides this.
- If a provider fails before the response starts, the request moves to the next provider, up to three. Failed attempts are not billed.
- An API key can be limited to some providers under **Allowed providers** in the console. Requests never leave that list.

## Differences from OpenRouter

- `vendor/model` names are mapped to AIxAPI IDs for `anthropic`, `openai`, `google`, `x-ai`, `deepseek`, `moonshotai`, `z-ai` and `qwen`.
- `latency` and `throughput` use the median of the last 24 hours of streaming requests. Providers without enough requests come last, ordered by success rate.
- Generation IDs come from the `X-Client-Request-ID` response header, not the response body `id`.
- `max_price`, `data_collection`, `zdr`, `quantizations`, `require_parameters` and `preferred_*` are accepted and ignored.
- An API key bound to a single group always uses that group; the `provider` object does not change it.
