# API Overview

> AnyRouter's REST API is a superset of the OpenAI API. Learn about base URLs, headers, error shapes, versioning, and the full list of endpoints.


# API Overview

The AnyRouter API is a **superset of the OpenAI API**. Any existing OpenAI tooling, SDK, or framework works out of the box — just override the base URL.

## Base URL

```text
https://anyrouter.dev/api/v1
```

All endpoints are versioned under `/v1`. Breaking changes bump the version (`/v2`) without removing older versions for a minimum 12-month deprecation window.

## Common headers

| Header | Required | Description |
|---|---|---|
| `Authorization: Bearer <key>` | Yes | AnyRouter API key. |
| `Content-Type: application/json` | POST | Required on POST endpoints. |
| `X-AnyRouter-Provider` | No | Force routing to a specific upstream provider. |
| `X-AnyRouter-Trace-Id` | No | Client-supplied trace id surfaced in audit logs. |

## Endpoints

| Method | Path | Description |
|---|---|---|
| POST | `/chat/completions` | [Chat completions](/docs/api-reference/chat-completions) (OpenAI-compatible) |
| POST | `/messages` | [Anthropic Messages](/docs/api-reference/messages) passthrough |
| POST | `/completions` | Legacy text completions |
| POST | `/embeddings` | Vector embeddings |
| GET | `/models` | [List models](/docs/api-reference/models) |
| GET | `/models/:id` | Model metadata |
| GET | `/models/count` | Total model count |
| POST | `/batch` | Submit batched requests |
| GET | `/generation/:id` | Per-request stats (tokens, cost, latency) |
| GET | `/providers` | List upstream providers |
| GET | `/credits` | Remaining credit balance |
| GET | `/auth/key` | Current API key info |
| GET | `/health` | Gateway + provider status |

## Error shape

All errors follow the OpenAI error envelope:

```json
{
  "error": {
    "message": "Rate limit exceeded for model openai/gpt-4-turbo",
    "type": "rate_limit_error",
    "code": "rate_limited",
    "param": null
  }
}
```

See [Errors](/docs/api-reference/errors) for the full list of codes and recommended retry behavior.

## Rate limits

Rate limits are enforced per-key. Every response carries:

```text
X-RateLimit-Limit:     <requests per minute>
X-RateLimit-Remaining: <remaining in current window>
X-RateLimit-Reset:     <unix seconds until window reset>
```

## Versioning

Changes are categorized as:

- **Additive** (new fields, new endpoints) — ship continuously, no notice.
- **Deprecation** — announced with a 12-month sunset window and `Deprecation` response header.
- **Breaking** — land on a new `/v2` path; `/v1` remains available for the deprecation window.
