Skip to content
Back to skills

Vercel Ai Gateway

ASecurity

Set up Vercel AI Gateway (@ai-sdk/gateway) for multi-provider AI access. Use when adding the gateway, switching AI providers, handling reasoning/thinking models, or mocking AI in tests.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 13, 2026
ai-agentstypescriptgoshellbashgitapi

Works with

  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned October 13, 2026

npx -y skills add phucbm/skills --skill vercel-ai-gateway --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vercel Ai Gateway?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Vercel Ai Gateway
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/phucbm-vercel-ai-gateway/badge)](https://www.skillsdirectory.com/skills/phucbm-vercel-ai-gateway)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: vercel-ai-gateway
description: Set up Vercel AI Gateway (@ai-sdk/gateway) for multi-provider AI access. Use when adding the gateway, switching AI providers, handling reasoning/thinking models, or mocking AI in tests.
when_to_use: When building an AI app that needs multi-provider support, reasoning middleware, or test isolation via mock provider.
allowed-tools: Bash Read Write Edit
---

# Vercel AI Gateway

`@ai-sdk/gateway` is a proxy layer that routes requests to multiple AI providers
(OpenAI, Anthropic, Google, xAI, GROQ) under a single API key.

```
Your app → Vercel AI Gateway (cloud proxy) → OpenAI / Anthropic / Google / xAI
```

Vercel hosts the proxy — you connect provider accounts in their dashboard.
On Vercel deployments: OIDC auto-auth, no key needed.
Locally: set `AI_GATEWAY_API_KEY`.

## Install
```shell
pnpm add @ai-sdk/gateway ai
```

## Basic usage
```typescript
import { gateway } from "@ai-sdk/gateway";

gateway.languageModel("google/gemini-2.5-flash-lite")
gateway.languageModel("anthropic/claude-haiku-4.5")
gateway.languageModel("openai/gpt-4o")
```
Model IDs follow `<provider>/<model-name>` format.

## Reasoning / thinking models
Apply `extractReasoningMiddleware` to models that emit `<thinking>` tags:

```typescript
import { gateway } from "@ai-sdk/gateway";
import { extractReasoningMiddleware, wrapLanguageModel } from "ai";

const THINKING_SUFFIX_REGEX = /-thinking$/;

export function getLanguageModel(modelId: string) {
  const isReasoning = modelId.includes("reasoning") || modelId.endsWith("-thinking");
  if (isReasoning) {
    return wrapLanguageModel({
      model: gateway.languageModel(modelId.replace(THINKING_SUFFIX_REGEX, "")),
      middleware: extractReasoningMiddleware({ tagName: "thinking" }),
    });
  }
  return gateway.languageModel(modelId);
}
```

## Test mock with customProvider
Swap real models for mocks via an env flag (e.g. `PLAYWRIGHT=True`):

```typescript
import { customProvider } from "ai";

export const myProvider = isTestEnvironment
  ? customProvider({
      languageModels: {
        "chat-model": mockChatModel,
        "title-model": mockTitleModel,
      },
    })
  : null;

export function getLanguageModel(modelId: string) {
  if (isTestEnvironment && myProvider) return myProvider.languageModel(modelId);
  return gateway.languageModel(modelId);
}
```

## Env
```env
AI_GATEWAY_API_KEY=    # not needed on Vercel (OIDC auto-auth)
```

## References
- food-tour-sg `lib/ai/providers.ts`: https://github.com/phucbm/food-tour-sg/blob/main/lib/ai/providers.ts
- Vercel AI SDK docs: https://ai-sdk.dev/docs/ai-sdk-core/providers-and-models
- `@ai-sdk/gateway` package: https://www.npmjs.com/package/@ai-sdk/gateway

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.