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