---
title: generate_ai_gateway_extraction
description: Use generate_ai_gateway_extraction with Vercel MCP.
url: "https://vercel.com/docs/agent-resources/vercel-mcp/tools/ai-gateway/generate_ai_gateway_extraction"
last_updated: 2018-10-20
related:
  - /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>"
---

# 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."

## 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.
