> ## Documentation Index
> Fetch the complete documentation index at: https://predev.mintlify.site/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: npx -y @predotdev/mcp setup adds it to every local coding agent with every pre.dev tool plus the user's own Chrome; the hosted server is https://api.pre.dev/mcp. Search these docs over MCP at https://docs.pre.dev/mcp.

# AI Gateway quickstart

> Send a chat completion through api.pre.dev/v1 with curl or a stock SDK.

Send one chat completion to `deepseek/deepseek-v4.1-flash` and read the credits it charged.

## Before you start

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_`.

Store it as `PREDEV_API_KEY`. A Free workspace can spend 5 credits on gateway calls in total, whatever its balance; after that, calls return `402` until the workspace subscribes. See [authentication](https://predev.mintlify.site/api-reference/authentication.md) and [pricing](https://predev.mintlify.site/coding-agent/plans-and-credits.md#ai-gateway-calls).

## Send a request

**curl**

```bash theme={null}
curl --fail-with-body https://api.pre.dev/v1/chat/completions \
  -H "Authorization: Bearer $PREDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek/deepseek-v4.1-flash",
    "messages": [{ "role": "user", "content": "Say hello in five words." }]
  }'
```

**Node.js**

Install the stock SDK with `npm install openai`, then set `baseURL`:

```typescript theme={null}
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.pre.dev/v1',
  apiKey: process.env.PREDEV_API_KEY!,
});

const completion = await client.chat.completions.create({
  model: 'deepseek/deepseek-v4.1-flash',
  messages: [{ role: 'user', content: 'Say hello in five words.' }],
});
console.log(completion.choices[0].message.content);
```

**Python**

Install the stock SDK with `pip install openai`, then set `base_url`:

```python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.pre.dev/v1",
    api_key=os.environ["PREDEV_API_KEY"],
)

completion = client.chat.completions.create(
    model="deepseek/deepseek-v4.1-flash",
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(completion.choices[0].message.content)
```

**Vercel AI SDK**

Install `ai` and `@ai-sdk/openai`, then create a provider with the gateway URL:

```typescript theme={null}
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';

const predev = createOpenAI({
  baseURL: 'https://api.pre.dev/v1',
  apiKey: process.env.PREDEV_API_KEY!,
});

const { text } = await generateText({
  model: predev('deepseek/deepseek-v4.1-flash'),
  prompt: 'Say hello in five words.',
});
console.log(text);
```

**Anthropic SDK**

The gateway serves the Anthropic Messages shape at `/v1/messages`. The Anthropic SDK appends `/v1/messages` itself, so its base URL is `https://api.pre.dev` **without** `/v1`. Use your pre.dev key as the API key:

```typescript theme={null}
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://api.pre.dev',
  apiKey: process.env.PREDEV_API_KEY!,
});

const message = await client.messages.create({
  model: 'anthropic/claude-sonnet-5',
  max_tokens: 256,
  messages: [{ role: 'user', content: 'Say hello in five words.' }],
});
console.log(message.content);
```

Model ids stay in catalog form (`anthropic/claude-sonnet-5`), not Anthropic's native names. See [Messages](https://predev.mintlify.site/ai-gateway/api/messages.md).

## Read the response

The body is a standard chat completion response. Three headers come from the gateway:

| Header | Meaning |
| - | - |
| `x-predev-request-id` | Gateway request id, `pdr_…`; quote it in support requests |
| `x-predev-credits-charged` | Credits charged for this call |
| `x-predev-credits-remaining` | Workspace balance after the call; omitted when the workspace has no credit limit |

Add `-i` to the curl command to print them. In the SDKs, use the raw-response helpers (`client.chat.completions.with_raw_response` in Python, `.withResponse()` in Node) when you need headers.

## Swap the model

> [!WARNING]
>
> **Reasoning models spend your `max_tokens` thinking.** Many models reason by default. With a small `max_tokens`, the reply can come back as `content: null` with `finish_reason: "length"` because the whole budget went to reasoning tokens, which are still billed. For chat, summarize, or classify features, pass `reasoning: { "enabled": false }` (or `{ "effort": "low" }`), or set `max_tokens` to at least 1024.

Change `model` to any id from [`GET /v1/models`](https://predev.mintlify.site/ai-gateway/api/models), for example `anthropic/claude-sonnet-5`, `google/gemini-3.8-flash`, or `openai/gpt-6-luna`. An id the catalog does not serve returns a `4xx` error; check the id against the catalog.

Continue with [streaming](https://predev.mintlify.site/ai-gateway/streaming.md), [tools and structured output](https://predev.mintlify.site/ai-gateway/tools-and-structured-output.md), or [fallbacks and advanced options](https://predev.mintlify.site/ai-gateway/routing-and-fallbacks.md).


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