macpaw/ai-sdk-typescript/integrate-ai-gateway

Claude Code and agent skill by macpaw/ai-sdk-typescript

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Integrate applications with AI Gateway using @macpaw/ai-sdk. Use for NestJS, Next.js, Vercel AI SDK, raw fetch migrations, video generation, voice listing, text-to-speech, credit balance queries, MacPaw AI, Setapp AI, createAIGatewayProvider, createGatewayFetch, createVideoClient, createVoiceClient, createSpeechClient, createCreditBalanceClient, and AI Gateway auth/error wiring.

Install

npx vskill@latest install macpaw/ai-sdk-typescript/integrate-ai-gateway

SKILL.md

AI Gateway Integration (@macpaw/ai-sdk)

Goal

Detect the app shape, choose one integration path, apply the smallest correct patch, add safe auth/error handling, run verification, and report exact changes.

Package surface

  • Use @macpaw/ai-sdk for createAIGatewayProvider, createGatewayProvider, createGatewayFetch, createVideoClient, createVoiceClient, createSpeechClient, createCreditBalanceClient, GATEWAY_PROVIDERS, errors, and GatewayProviderSettings.
  • Use @macpaw/ai-sdk/provider only as a compatibility alias.
  • Use @macpaw/ai-sdk/nestjs for AIGatewayModule, @InjectAIGateway(), and AIGatewayExceptionFilter.
  • Do not use createAIGatewayClient, @macpaw/ai-sdk/client, runtime, types, or testing; they do not exist.
  • For UI hooks or schema helpers, follow the versioned upstream docs for the installed ai / @ai-sdk/react major version; this package does not redefine those APIs.

Guardrails

  • Do not invent a token source. If server-side token retrieval is unclear, ask one question.
  • Do not place real tokens in browser-only code. Frontend-only apps need a backend/BFF token source.
  • Do not remove direct OpenAI/Anthropic paths unless all usages are migrated or the user asked for it.
  • Use baseURL for staging/custom hosts. env supports only 'production'.
  • createGatewayFetch requires a resolved baseURL; do not pass only env. Prefer resolveGatewayBaseURL() when you want the default production host.

Choose one path

  • NestJS markers: @nestjs/common, *.module.ts, decorators -> use @macpaw/ai-sdk/nestjs + @macpaw/ai-sdk.
  • Next.js / Vercel markers: next, ai, @ai-sdk/* -> keep generation on ai, swap only the model provider.
  • Express/Fastify/Hono/server scripts -> use createGatewayFetch, or ai + provider if already Vercel-shaped.
  • Video generation (create job, poll status, fetch content) -> use createVideoClient.
  • Voice listing (paginated GET /v1/voices) -> use createVoiceClient.
  • Speech generation (streaming text-to-speech, POST /v1/audio/speech) -> use createSpeechClient.
  • Credit balance queries (active balances, totals) -> use createCreditBalanceClient.
  • Existing openai, @ai-sdk/openai, or @anthropic-ai/sdk usage -> treat as migration, not greenfield.

Canonical patterns

ts
// Vercel AI SDK
const gateway = createAIGatewayProvider({
env: 'production',
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
});
const result = streamText({ model: gateway('openai/gpt-4o'), messages });
ts
// NestJS
AIGatewayModule.forRootAsync({
useFactory: () => ({
env: 'production',
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
}),
});
constructor(@InjectAIGateway() private readonly config: GatewayProviderSettings) {}
ts
// Raw fetch / multipart
const baseURL = process.env.AI_GATEWAY_BASE_URL ?? 'https://api.macpaw.com/ai';
const gatewayFetch = createGatewayFetch({
baseURL,
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
});
ts
// Video generation
const videos = createVideoClient({
env: 'production',
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
});
const job = await videos.create({ model: 'veo-2', prompt: 'A sunset over the ocean' });
ts
// Voice listing
const voices = createVoiceClient({
env: 'production',
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
});
const page = await voices.list({ provider: 'elevenlabs' });
ts
// Speech generation (streaming only — never a single buffered audio file)
const speech = createSpeechClient({
env: 'production',
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
});
const response = await speech.create({ model: 'openai/gpt-4o-mini-tts', input: 'Hello', voice: 'alloy' });
ts
// Credit balance
const balance = createCreditBalanceClient({
env: 'production',
getAuthToken: async () => process.env.AI_GATEWAY_TOKEN ?? null,
});
const { data } = await balance.getBalances();
console.log(data.totalAvailable.amount); // e.g. "1000000"

Error handling

  • Prefer isAIGatewayError(error) and switch on ErrorCode.
  • Use AIGatewayExceptionFilter in NestJS.
  • Treat InsufficientCredits / SubscriptionExpired as the billing states; there is no PaymentRequired.

Migration rules

  • Keep generateText, streamText, embed, React hooks, and upstream primitives on ai / @ai-sdk/*.
  • Replace direct gateway-bound provider construction with createAIGatewayProvider or createGatewayProvider.
  • Replace raw HTTP gateway calls with createGatewayFetch.
  • Remove old dependencies only after verifying there are no remaining imports/usages.

Verification

  • Read package.json scripts before running commands.
  • Prefer typecheck, lint, test, and build when available.
  • Add one focused smoke path: provider call, route handler, or fetch stub.
  • Do not claim success without reporting which verification commands actually ran.

Output contract

  • State the chosen path: NestJS, Vercel, or raw fetch.
  • List files changed.
  • State where the token now comes from.
  • State verification run and any manual env step left.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
58
Repository forks
1
Repository npm downloads, 7 days
114
7-day trend score
32

Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 14 Aug 2026, 2 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/macpaw/ai-sdk-typescript/integrate-ai-gateway/badge)](https://verified-skill.com/skills/macpaw/ai-sdk-typescript/integrate-ai-gateway)

Something wrong with this skill or its page? Tell us.