# AI Gateway

> One key, every model, with a hard budget — in one command.

```bash
npx extraorbital add ai --max-budget 10
```

```txt
✓ Provisioned openrouter/default ($10.00 budget)
✓ Wrote 2 variables to .env

  OPENROUTER_BASE_URL, OPENROUTER_API_KEY
```

One key reaches every model on the gateway — Anthropic, OpenAI, Google, Meta,
Mistral, DeepSeek, Qwen and the rest, [400-odd in
total](/docs/resources/ai-gateway/models). A project that mentions any AI
provider's key gets this from [`extraorbital
provision`](/docs/quickstart#how-autopilot-decides). Name a budget and it is a
hard ceiling; leave it out and the key is uncapped on [a paid plan](/pricing), or
held to whatever is left of your allowance on Prototype.

## What it writes

| Variable | Example |
| --- | --- |
| `OPENROUTER_BASE_URL` | `https://openrouter.ai/api/v1` |
| `OPENROUTER_API_KEY` | `sk-or-v1-9c4e17b2…` |

The key is a real OpenRouter credential, used directly against `openrouter.ai`.
Nothing is proxied through us, so your inference never depends on our uptime —
and the budget is enforced by OpenRouter itself rather than by a control loop
somewhere that has to still be running.

## Model ids

Every model is named `author/slug`:

```txt
anthropic/claude-opus-5
openai/gpt-5.2
google/gemini-3-pro
```

Append `:free` for a free variant where one exists, and `~author/…-latest` for
an alias that follows the newest release. The [model
list](/docs/resources/ai-gateway/models) has all of them with current prices.

## Options

```bash
npx extraorbital add ai [--slug <name>] [--max-budget <usd>] [--model-tier <tier>]
```

| Flag | Default | Description |
| --- | --- | --- |
| `--slug` | `default` | A second key with its own budget |
| `--max-budget` | none | Hard cap in USD. Requests past it fail on budget, not on auth |
| `--model-tier` | `full` | `small` restricts the key to the cheapest models |

There is no default budget on a paid plan: an unasked-for ceiling would only stop
a working agent at an arbitrary number. Set `--max-budget` when you want a hard
per-key stop, and set an account-wide cap from the [dashboard](/dashboard) when
you want one number to bound everything at once.

Separate slugs give separate budgets, which is how you keep an experimental agent
from eating a production one's allowance:

```bash
npx extraorbital add ai --slug experiments --max-budget 2
```

`--max-budget 0` stops the spend without revoking the key. Requests fail on
budget rather than breaking with an auth error nobody can interpret, and raising
the ceiling brings the same key back.

## Prototype allowance

**The first $5.00 of small models is on us**, granted once per account rather
than every month. A Prototype key is minted for the cheap models only and cannot
spend past the allowance, whatever budget the agent asks for. On [a paid
plan](/pricing) a key reaches every model and meters at the model's list price
with nothing added.

This is the one resource that meters per request, so the ledger shows real
numbers from the first call rather than a provisioning entry at $0.00.

## Use it

The gateway speaks the OpenAI API, so most clients need no adapter:

```ts title="agent.ts"
import OpenAI from "openai";

// Reads OPENROUTER_API_KEY and OPENROUTER_BASE_URL from the environment.
const client = new OpenAI({
  apiKey: process.env.OPENROUTER_API_KEY,
  baseURL: process.env.OPENROUTER_BASE_URL,
});

const response = await client.chat.completions.create({
  model: "anthropic/claude-opus-5",
  messages: [{ role: "user", content: "Draft a status report from these logs." }],
});
```

It also speaks the Anthropic Messages API, which is what lets Claude Code point
at it. [SDK recipes](/docs/resources/ai-gateway/sdks) has both, plus the Vercel
AI SDK, LangChain, Hermes and raw `curl`.

## If you asked for a provider key

`extraorbital add openai` does not mint an OpenAI key — nobody but OpenAI can.
It provisions the gateway, points `OPENAI_BASE_URL` at it so your existing code
runs unchanged, explains what happened, and **exits `8`**. Everything else in the
same command still gets provisioned first.

[Providers and keys](/docs/resources/ai-gateway/providers) lists every variable
name this applies to and what gets written for each.

## Next

- [Providers and keys](/docs/resources/ai-gateway/providers) — every key we recognise
- [Models](/docs/resources/ai-gateway/models) — the full list, with prices
- [SDK recipes](/docs/resources/ai-gateway/sdks) — how to call it from anything
- [Pricing](/pricing) — plans, allowances and rates

---

More for agents: [Docs index](https://extraorbital.dev/sitemap.md) · [llms.txt](https://extraorbital.dev/llms.txt) · [agents.md](https://extraorbital.dev/agents.md)
