---
title: AI Gateway
description: Vercel MCP tools that run AI Gateway models.
url: "https://vercel.com/docs/agent-resources/vercel-mcp/tools/ai-gateway"
last_updated: 2018-10-20
related:
  - /docs/ai-gateway
  - /docs/ai-gateway/modalities/decision
  - /docs/ai-gateway/modalities/extraction
  - /docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_text
  - /docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_decision
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# AI Gateway

Run [AI Gateway](/docs/ai-gateway) models from your AI assistant. Send a conversation to a text model, generate images from a prompt, ask a [decision model](/docs/ai-gateway/modalities/decision) typed questions with calibrated probabilities, and pull typed fields out of text, PDFs, and images with an [extraction model](/docs/ai-gateway/modalities/extraction). Unlike the rest of the tools reference, these tools run models, so each call is billed to the AI Gateway credits of the team named in `teamId`, and a call on a connection bound to a team is billed to that team. The tools authenticate with your existing Vercel MCP sign-in, so no AI Gateway API key is needed. An agent can chain them in one session, such as generating images and then scoring them with a decision call. Browse models and prices at the [AI Gateway models page](/ai-gateway/models).

## `generate_ai_gateway_decision`

Asks a [decision model](/docs/ai-gateway/modalities/decision) on Vercel AI Gateway typed questions about one input, and returns calibrated probabilities instead of free text. The input is text, plus optional JSON data or images. For each question in order, the tool returns a yes probability (predicate), the chosen option with its probabilities (choice), or a score on an ordered scale (score).

Use `generate_ai_gateway_decision` to classify, route, verify, or score. For example, whether a message asks for a refund, which team should handle a ticket, how urgent it is, or whether a screenshot shows an error. Ask every question about the same input in one call. For free-form answers, use [`generate_ai_gateway_text`](/docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_text) instead.

Each call runs a model on AI Gateway and is billed to the AI Gateway credits of the team in `teamId`, and a fallback rerun is billed too. The call authenticates with your Vercel MCP sign-in, so no AI Gateway API key is needed.

## Parameters

| Parameter           | Type            | Required | Description                                                                                                                                                                                                                                                  |
| ------------------- | --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `teamId`            | string          | Yes      | The ID (`team_...`) or slug of the team whose AI Gateway credits pay for the call. Use `list_teams` to discover an unknown team. A connection bound to a team is billed to that team.                                                                        |
| `model`             | string          | No       | The decision model ID as `creator/model`, such as `typesafe-ai/jev`. Defaults to `openai/gpt-6-luna-decisions`. Image input needs a model that accepts images. Use `list_ai_gateway_models` with type `evaluation` to find decision models and their prices. |
| `input`             | string          | Yes      | The text every question is asked about, such as a support ticket, a log excerpt, or a code diff. The `input`, `data`, and `questions` together may total at most 200,000 characters.                                                                         |
| `data`              | object \| array | No       | Optional structured data asked about along with `input`, as a JSON object or a non-empty array of objects, such as `{ "order": { "id": "A-1", "status": "refunded" } }`.                                                                                     |
| `images`            | array           | No       | Optional images asked about along with `input`, up to 4. Each is `{ url, detail? }`. See [Image object](#image-object).                                                                                                                                      |
| `questions`         | array           | Yes      | 1 to 20 questions in order. Answers come back in the same order. See [Question object](#question-object).                                                                                                                                                    |
| `zeroDataRetention` | boolean         | No       | Route only to providers with zero data retention. Use when the input is sensitive.                                                                                                                                                                           |
| `fallback`          | object          | No       | Optional confidence fallback that reruns the decision with another model when an answer is uncertain. See [Fallback object](#fallback-object).                                                                                                               |

### Image object

Each entry in `images` describes one image asked about along with `input`.

| Property | Type   | Required | Description                                                                                            |
| -------- | ------ | -------- | ------------------------------------------------------------------------------------------------------ |
| `url`    | string | Yes      | The image as a base64 data URL (`png`, `jpeg`, `webp`, or `gif`). External URLs are not supported.     |
| `detail` | string | No       | How much image detail the model uses. One of `low`, `high`, `auto`, or `original`.                     |

### Question object

Each entry in `questions` is one typed question asked about the same input. Answers come back in the same order. A question the model declines comes back as type `refusal`.

| Property       | Type   | Required | Description                                                                                                                 |
| -------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `type`         | string | Yes      | `predicate` for yes or no, `choice` to pick one option, or `score` to rate on an ordered scale.                             |
| `instructions` | string | Yes      | The question to ask, up to 2,000 characters.                                                                                |
| `name`         | string | No       | A unique name that keys this question's answer, up to 64 characters.                                                        |
| `choices`      | array  | No       | Required for a `choice` question. 1 to 255 options as `{ value, description? }`, where `value` is a string or boolean.      |
| `levels`       | array  | No       | Required for a `score` question. The scale from lowest to highest as 2 to 10 `{ label, description? }` entries.             |

### Fallback object

Reruns the decision with another model when an answer is uncertain. A rerun is billed too, and fallback answers carry no confidence.

| Property             | Type   | Required | Description                                                                                                                                                  |
| -------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`              | string | Yes      | The model that reruns every question when the condition matches.                                                                                             |
| `question`           | string | No       | Names one question to check. Omit it to check every question of the matching type.                                                                           |
| `confidenceBelow`    | number | No       | Rerun when a `choice` or `score` answer has confidence below this, from `0` to `1`. Set exactly one of `confidenceBelow` or `probabilityBetween`.            |
| `probabilityBetween` | array  | No       | Rerun when a `predicate` yes probability is within this inclusive range, such as `[0.4, 0.6]`. Set exactly one of `confidenceBelow` or `probabilityBetween`. |

## Returns

| Field          | Description                     |
| -------------- | ------------------------------- |
| `answers`      | The answers in question order.  |
| `model`        | The model that answered.        |
| `usage`        | Token usage for the call.       |
| `cost`         | The cost of the call.           |
| `generationId` | The ID of the generation.       |

Sample prompt: "Does this support ticket ask for a refund, and how urgent is it?"

## `generate_ai_gateway_extraction`

Asks an [extraction model](/docs/ai-gateway/modalities/extraction) on Vercel AI Gateway for named fields from text, PDFs, or images, and returns one typed answer per field. Use it to pull the invoice number, vendor, and line items from an invoice, the parties from a contract, or the names from an email. Request every field from the same input in a single call.

For free-form summaries or answers, use [`generate_ai_gateway_text`](/docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_text). To classify or score an input, use [`generate_ai_gateway_decision`](/docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_decision).

Each call runs a model on AI Gateway and is billed to the AI Gateway credits of the team in `teamId`. The call authenticates with your Vercel MCP sign-in, so no AI Gateway API key is needed.

## Parameters

| Parameter | Type   | Required | Description                                                                                                                                                                           |
| --------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `teamId`  | string | Yes      | The ID (`team_...`) or slug of the team whose AI Gateway credits pay for the call. Use `list_teams` to discover an unknown team. A connection bound to a team is billed to that team. |
| `model`   | string | No       | The extraction model ID as `creator/model`. Defaults to `scaledown/extract-1`. Use `list_ai_gateway_models` with type `extraction` to find other extraction models and their prices.  |
| `text`    | string | No       | The text to extract from, such as an invoice, a contract, or an email. Pass text, files, or both. The text and fields together may total at most 200,000 characters.                  |
| `files`   | array  | No       | PDFs or images to extract from, up to 4. See [File input](#file-input) for the shape of each entry.                                                                                   |
| `fields`  | array  | Yes      | 1 to 20 fields to extract. See [Field definition](#field-definition) for the shape of each entry.                                                                                     |

### File input

Each entry in `files` is an object with a single `url`.

| Property | Type   | Required | Description                                                                                                                                                |
| -------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`    | string | Yes      | The file as a base64 data URL, either a PDF (`data:application/pdf;base64,…`) or a `png`, `jpeg`, `webp`, or `gif` image. External URLs are not supported. |

Answers from a file give the file part but no character position.

### Field definition

Each entry in `fields` describes one field to extract.

| Property       | Type   | Required | Description                                                                                       |
| -------------- | ------ | -------- | --------------------------------------------------------------------------------------------------- |
| `name`         | string | Yes      | A unique name that keys the answer for this field, up to 64 characters, such as `invoiceNumber`.  |
| `type`         | string | Yes      | `text` for one value, or `list` for every matching value, such as all contact names.              |
| `instructions` | string | Yes      | What to find, up to 2,000 characters, such as `"The invoice number"`.                             |

## Returns

The result has an `answers` object with one entry per field `name`. Each answer has:

| Field        | Description                                                                |
| ------------ | -------------------------------------------------------------------------- |
| `type`       | The answer type. A field the model declines comes back as type `refusal`. |
| `value`      | The extracted value, or `null` when the input does not contain it.        |
| `confidence` | A score from 0 to 1.                                                      |

A `text` answer from text input includes where the value appears. A `list` answer has one `items` entry per value. The result also includes the `model`, token `usage`, `cost`, and a `generationId`.

Sample prompt: "Extract the invoice number and contact names from this invoice PDF."

## `generate_ai_gateway_image`

Creates new images from a text description, such as an illustration, icon, mockup, or photo, by running an image model on [AI Gateway](/docs/ai-gateway). The tool returns the generated images as MCP image content with a short JSON summary covering the team, model, image count, and usage.

This tool runs image-only models. Multimodal models that generate images through chat, such as `google/gemini-3-pro-image`, are not supported. It does not edit or describe existing images.

Each call runs a model on AI Gateway and is billed to the AI Gateway credits of the team in `teamId`, and every image is billed. The call authenticates with your Vercel MCP sign-in, so no AI Gateway API key is needed.

## Parameters

| Parameter      | Type   | Required | Description                                                                                                                                                                           |
| -------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `teamId`       | string | Yes      | The ID (`team_...`) or slug of the team whose AI Gateway credits pay for the call. Use `list_teams` to discover an unknown team. A connection bound to a team is billed to that team. |
| `prompt`       | string | Yes      | A description of the image to create, up to 4,000 characters.                                                                                                                         |
| `model`        | string | No       | The image model ID as `creator/model`. Defaults to `openai/gpt-image-2`. Use `list_ai_gateway_models` with type `image` to find other models and their prices.                        |
| `n`            | number | No       | Number of images to create, up to 4. Defaults to 1. Each image is billed.                                                                                                             |
| `size`         | string | No       | Image size as `WIDTHxHEIGHT`, such as `1024x1024` or `1536x1024`. Omit for the model default. Supported sizes vary by model.                                                          |
| `quality`      | string | No       | Rendering quality, for models that support it. One of `auto`, `high`, `medium`, or `low`.                                                                                             |
| `outputFormat` | string | No       | The image file format, one of `png`, `jpeg`, or `webp`. Defaults to `jpeg`, which keeps responses small. Use `png` for transparency or lossless output.                               |

## Limits

Results return in one response capped at 4.4 MB. The tool refuses up front any count, size, and format combination that could exceed this cap. If a request is refused, ask for fewer images, a smaller size, or `jpeg` or `webp` output.

Sample prompt: "Generate a 1024x1024 icon of a rocket in flat design."

## `generate_ai_gateway_text`

Sends a conversation to a chosen model on [AI Gateway](/docs/ai-gateway) and returns its text reply, finish reason, and token usage. Use it to ask another model for a second opinion or to compare how models respond to the same prompt. To compare models, call the tool once per model with the same `messages`.

This tool handles text only. It sends and receives no files, images, or tool calls. For yes/no, classification, or scoring questions that need probabilities, use [`generate_ai_gateway_decision`](/docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_decision) instead.

Each call runs a model on AI Gateway and is billed to the AI Gateway credits of the team in `teamId`. The call authenticates with your Vercel MCP sign-in, so you don't need an AI Gateway API key.

## Parameters

| Parameter         | Type   | Required | Description                                                                                                                                                                                                                                                                          |
| ----------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `teamId`          | string | Yes      | The ID (`team_...`) or slug of the team whose AI Gateway credits pay for the call. Use `list_teams` to discover an unknown team. A connection bound to a team is billed to that team.                                                                                                |
| `model`           | string | Yes      | The model ID as `creator/model`, such as `anthropic/claude-sonnet-5` or `openai/gpt-5`. Use `list_ai_gateway_models` with type `language` to find model IDs and prices.                                                                                                              |
| `messages`        | array  | Yes      | The conversation in order, ending with the user message to answer. 1 to 50 messages, each `{ role: "user" \| "assistant", content: string }` with `content` up to 100,000 characters. All messages and the system message together may total at most 200,000 characters. Pass earlier turns to continue a conversation. |
| `system`          | string | No       | Instructions for the model, sent as a system message. Up to 100,000 characters.                                                                                                                                                                                                      |
| `maxOutputTokens` | number | No       | Maximum tokens in the reply, up to 32,000. Defaults to 8,000. A reply that hits the limit has `finishReason` `length`. Reasoning models count their thinking against this limit.                                                                                                     |
| `temperature`     | number | No       | Sampling temperature from 0 to 2, for models that support it.                                                                                                                                                                                                                        |

## Returns

A successful call returns the reply `text`, the `finishReason`, the `model` that answered, token `usage`, and a `generationId`. When the model declines to answer, the result includes a `refusal`.

A reply cut off by the 100-second time limit, a dropped connection, or a provider error still returns the text written so far, with `finishReason` set to `timeout`, `interrupted`, or `error`, `incomplete: true`, a `providerError` when the provider reported one, and a note on how to continue. The call may still be billed in full, so don't retry it unchanged.

Sample prompt: "Ask openai/gpt-5 for a second opinion on this error message."

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
