
Ai Sdk
Wires Vercel AI Gateway authentication and model selection into AI SDK generateText calls without hard-coding stale model IDs.
Overview
ai-sdk is an agent skill for the Build phase that shows how to authenticate and call models through Vercel AI Gateway with the Vercel AI SDK.
Install
npx skills add https://github.com/vercel-labs/open-agents --skill ai-sdkWhat is this skill?
- Documents OIDC for Vercel deploys and AI_GATEWAY_API_KEY for local .env.local auth
- Shows default global provider usage plus explicit gateway imports from ai or @ai-sdk/gateway
- Requires fetching live model list from https://ai-gateway.vercel.sh/v1/models—never memory-cached IDs
- Single API surface for OpenAI, Anthropic, Google, and other gateway-backed models
- TypeScript-first examples using generateText from the ai package
- Live model discovery endpoint: ai-gateway.vercel.sh/v1/models
- 2 documented gateway import options (ai package vs @ai-sdk/gateway)
Adoption & trust: 27 installs on skills.sh; 5.6k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You want multi-provider LLM access in your app but keep guessing wrong model strings and juggling separate API setups.
Who is it for?
Indie builders shipping AI features on Vercel who standardize on the AI SDK and AI Gateway.
Skip if: Self-hosted inference stacks, non-TypeScript-only shops avoiding Vercel, or teams that need fine-tuning pipelines rather than hosted inference.
When should I use this skill?
Implementing or updating Vercel AI Gateway usage with the AI SDK in application code.
What do I get? / Deliverables
You configure gateway auth, import generateText correctly, and select models from the live gateway catalog for working TypeScript calls.
- Working generateText snippet with gateway model string
- .env.local AI_GATEWAY_API_KEY configuration pattern
- Process to validate model IDs against gateway /v1/models
Recommended Skills
Journey fit
Gateway and SDK integration happens while implementing server-side or edge AI features during product build. Backend is the shelf because the skill centers on API keys, providers, and generateText usage—not marketing or launch distribution.
How it compares
Reference skill for AI SDK + Gateway—not an MCP server and not a full agent orchestration framework.
Common Questions / FAQ
Who is ai-sdk for?
Developers using Vercel AI Gateway and the AI SDK who want copy-paste-correct auth and model invocation patterns.
When should I use ai-sdk?
During Build (backend) when adding generateText calls, rotating gateway keys, or refreshing which provider/model IDs are available.
Is ai-sdk safe to install?
Review the Security Audits panel on this page; never commit AI_GATEWAY_API_KEY and scope network access to gateway endpoints only.
SKILL.md
READMESKILL.md - Ai Sdk
# Vercel AI Gateway The Vercel AI Gateway is the fastest way to get started with the AI SDK. It provides access to models from OpenAI, Anthropic, Google, and other providers through a single API. ## Authentication Authenticate with OIDC (for Vercel deployments) or an [AI Gateway API key](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway%2Fapi-keys&title=AI+Gateway+API+Keys): ```env filename=".env.local" AI_GATEWAY_API_KEY=your_api_key_here ``` ## Usage The AI Gateway is the default global provider, so you can access models using a simple string: ```ts import { generateText } from 'ai'; const { text } = await generateText({ model: 'anthropic/claude-sonnet-4.5', prompt: 'What is love?', }); ``` You can also explicitly import and use the gateway provider: ```ts // Option 1: Import from 'ai' package (included by default) import { gateway } from 'ai'; model: gateway('anthropic/claude-sonnet-4.5'); // Option 2: Install and import from '@ai-sdk/gateway' package import { gateway } from '@ai-sdk/gateway'; model: gateway('anthropic/claude-sonnet-4.5'); ``` ## Find Available Models **Important**: Always fetch the current model list before writing code. Never use model IDs from memory - they may be outdated. List all available models through the gateway API: ```bash curl https://ai-gateway.vercel.sh/v1/models ``` Filter by provider using `jq`. **Do not truncate with `head`** - always fetch the full list to find the latest models: ```bash # Anthropic models curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("anthropic/")) | .id] | reverse | .[]' # OpenAI models curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("openai/")) | .id] | reverse | .[]' # Google models curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("google/")) | .id] | reverse | .[]' ``` When multiple versions of a model exist, use the one with the highest version number (e.g., prefer `claude-sonnet-4-5` over `claude-sonnet-4` over `claude-3-5-sonnet`). --- title: Common Errors description: Reference for common AI SDK errors and how to resolve them. --- # Common Errors ## `maxTokens` → `maxOutputTokens` ```typescript // ❌ Incorrect const result = await generateText({ model: 'anthropic/claude-opus-4.5', maxTokens: 512, // deprecated: use `maxOutputTokens` instead prompt: 'Write a short story', }); // ✅ Correct const result = await generateText({ model: 'anthropic/claude-opus-4.5', maxOutputTokens: 512, prompt: 'Write a short story', }); ``` ## `maxSteps` → `stopWhen: stepCountIs(n)` ```typescript // ❌ Incorrect const result = await generateText({ model: 'anthropic/claude-opus-4.5', tools: { weather }, maxSteps: 5, // deprecated: use `stopWhen: stepCountIs(n)` instead prompt: 'What is the weather in NYC?', }); // ✅ Correct import { generateText, stepCountIs } from 'ai'; const result = await generateText({ model: 'anthropic/claude-opus-4.5', tools: { weather }, stopWhen: stepCountIs(5), prompt: 'What is the weather in NYC?', }); ``` ## `parameters` → `inputSchema` (in tool definition) ```typescript // ❌ Incorrect const weatherTool = tool({ description: 'Get weather for a location', parameters: z.object({ // deprecated: use `inputSchema` instead location: z.string(), }), execute: async ({ location }) => ({ location, temp: 72 }), }); // ✅ Correct const weatherTool = tool({ description: 'Get weather for a location', inputSchema: z.object({ location: z.string(), }), execute: async ({ location }) => ({ location, temp: 72 }), }); ``` ## `generateObject` → `generateText` with `output` `generateObject` is deprecated. Use `generateText` with the `output` option instead. ```typescript // ❌ Deprecated import { generateObject } from 'ai'; // deprecated: use `generateText`