> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pre.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Agents: start with https://docs.pre.dev/agents.md, which has complete recipes, plan access, polling rules, errors and limits.
> Authenticate with the workspace API key (pdk_…) from Integrations → Built-in, sent as Authorization: Bearer <key>.
> REST API: https://api.pre.dev (OpenAPI: https://docs.pre.dev/api-reference/openapi.json). AI Gateway: https://api.pre.dev/v1, OpenAI-compatible (OpenAPI: https://docs.pre.dev/api-reference/ai-gateway.openapi.json).
> pre.dev MCP server: https://api.pre.dev/mcp. Search these docs over MCP at https://docs.pre.dev/mcp.

# AI Gateway

> Call hundreds of models from every major lab through api.pre.dev/v1 with your pre.dev key and credits.

The pre.dev AI Gateway is an OpenAI-compatible API for hundreds of models from every major lab. Point an OpenAI-compatible client at the AI Gateway base URL, send your pre.dev API key, and call any model in the pre.dev catalog by the id listed in [`GET /v1/models`](/ai-gateway/api/models). Calls are paid with pre.dev credits.

| Interface | Base URL |
| - | - |
| REST: specifications, browser tasks, and credits | `https://api.pre.dev` |
| AI Gateway | `https://api.pre.dev/v1` |
| MCP server | `https://api.pre.dev/mcp` |

Copy your pre.dev API key from **Integrations → Built-in** in the dashboard: [pre.dev/projects/integrations](https://pre.dev/projects/integrations?tab=built-in) for your personal workspace, or the Integrations page of a team workspace. Workspace keys start with `pdk_`.

<CardGroup cols={2}>
  <Card title="Quickstart" icon="play" href="/ai-gateway/quickstart">
    First request with curl, the OpenAI SDK, the Vercel AI SDK, or the Anthropic SDK.
  </Card>

  <Card title="In apps you build" icon="code" href="/coding-agent/built-in#ai">
    Call models from apps built on pre.dev, with the key already in place.
  </Card>

  <Card title="Pricing" icon="coins" href="/coding-agent/plans-and-credits#ai-gateway-calls">
    Credits per call, the free allowance, and what happens when credits run out.
  </Card>

  <Card title="Models" icon="list" href="/ai-gateway/models">
    Browse the catalog with credit prices attached.
  </Card>
</CardGroup>

## How a call is handled

<img className="block dark:hidden" src="https://mintcdn.com/predev/7eUhmIdZncrpx3fC/images/diagrams/gateway-routing-light.svg?fit=max&auto=format&n=7eUhmIdZncrpx3fC&q=85&s=a18bf21a0cb459a57add2cf54030f5f5" alt="How the AI Gateway handles a call: it authenticates your pre.dev key, admits the call only with enough credits and under the rate limit, routes it to the model you named or your fallback list, and charges credits when the response finishes." width="540" height="732" data-path="images/diagrams/gateway-routing-light.svg" />

<img className="hidden dark:block" src="https://mintcdn.com/predev/7eUhmIdZncrpx3fC/images/diagrams/gateway-routing-dark.svg?fit=max&auto=format&n=7eUhmIdZncrpx3fC&q=85&s=9c8ced6e27cc4f85dad5cb765ce9a2d7" alt="How the AI Gateway handles a call: it authenticates your pre.dev key, admits the call only with enough credits and under the rate limit, routes it to the model you named or your fallback list, and charges credits when the response finishes." width="540" height="732" data-path="images/diagrams/gateway-routing-dark.svg" />

1. **Authenticate.** Your pre.dev key, sent as `Authorization: Bearer` or `x-api-key`, identifies the workspace. A missing or invalid key returns `401`.
2. **Admit.** The call needs enough credits and must stay under the workspace rate limit. Otherwise it returns `402` or `429`, and no model runs.
3. **Route.** The model you named answers, or the models in your [`models` list](/ai-gateway/routing-and-fallbacks#fallback-models), tried in order. You choose the model; pre.dev chooses how to serve it.
4. **Charge.** Credits for the call's metered usage are charged once the response or stream finishes. See [response headers](#response-headers) for how the charge is reported.

## What you send

Model ids are `<author>/<slug>` strings exactly as listed by [`GET /v1/models`](/ai-gateway/api/models), for example `anthropic/claude-sonnet-5`, `deepseek/deepseek-v4.1-flash`, `google/gemini-3.8-flash`, or `openai/gpt-6-luna`. There are no separate pre.dev-specific model names.

The standard chat completion fields (`messages`, `temperature`, `max_tokens`, `stop`, and so on) work as you would expect. The pre.dev AI API also supports these options, described on [fallbacks and advanced options](/ai-gateway/routing-and-fallbacks):

| Field | Purpose |
| - | - |
| `models`, `route` | Fallback model list |
| `transforms` | Prompt transforms |
| `reasoning`, `reasoning_effort` | Reasoning controls |
| `plugins` | `web`, `file-parser`, `response-healing`, `context-compression` |
| `web_search_options` | Web search settings |
| `response_format`, `structured_outputs` | JSON and schema-constrained output |
| `tools`, `tool_choice`, `parallel_tool_calls` | Tool calling |
| `prediction`, `verbosity`, `session_id` | Predicted outputs, verbosity, session grouping |
| `stream` | Server-sent event streaming |

## What you get back

Responses use the standard OpenAI-compatible shapes, and the Anthropic Messages shape on `/v1/messages`. Model responses carry a pre.dev generation id (`pdg-…`) and token counts in `usage`. Streaming chat completions end with a chunk that carries `usage`.

## Endpoints

| Method | Path | Reference |
| - | - | - |
| POST | `/v1/chat/completions`, `/v1/completions`, `/v1/responses` | [Chat completions](/ai-gateway/api/chat-completions) |
| POST | `/v1/messages` | [Messages](/ai-gateway/api/messages) |
| POST | `/v1/embeddings`, `/v1/rerank` | [Embeddings and rerank](/ai-gateway/api/embeddings) |
| POST, GET | `/v1/images`, `/v1/videos`, `/v1/videos/{jobId}`, `/v1/videos/{jobId}/content` | [Images and video](/ai-gateway/api/images-and-video) |
| POST | `/v1/audio/speech`, `/v1/audio/transcriptions` | [Audio](/ai-gateway/api/audio) |
| POST, GET, DELETE | `/v1/files`, `/v1/files/{id}`, `/v1/files/{id}/content` | [Files](/ai-gateway/api/files) |
| GET | `/v1/models`, `/v1/models/count`, `/v1/embeddings/models`, `/v1/images/models`, `/v1/videos/models` | [Model catalog](/ai-gateway/api/models) |
| GET | `/v1/usage`, `/v1/generation` | [Usage](/ai-gateway/api/usage) |

Any other `/v1` path returns `404`.

## Response headers

Every inference call returns `x-predev-request-id` (`pdr_…`). Completed non-streaming calls also return `x-predev-credits-charged` and `x-predev-credits-remaining` (omitted when the workspace has no credit limit). Streamed calls carry only the request id; read their charge from [`GET /v1/usage`](/ai-gateway/api/usage#usage-totals) or [`GET /v1/generation`](/ai-gateway/api/usage#one-generation). Send `x-predev-project-id` to attribute usage to one of your projects.

## Billing

Each call is charged in credits from the model's metered usage for that call. The credit price per model is listed on [`GET /v1/models`](/ai-gateway/api/models) under `predev.credits_per_m_input` and `predev.credits_per_m_output`. Catalog reads are free. Details and the free allowance are on [pricing](/coding-agent/plans-and-credits#ai-gateway-calls).


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