AI Provider Setup (Vercel AI Gateway)

Wire the Vercel AI Gateway for text and cover image generation.

Last updated:

Create an AI Gateway key

  1. Open your Vercel project → AI Gateway tab
  2. Click Create Key and give it a clear name
  3. Copy the key (starts with vck_)
  4. Add it to your env file:
.env
AI_GATEWAY_API_KEY=vck_...

Note

Vercel grants $5 of free AI Gateway credits on signup. Usage across providers is billed through your Vercel account — no separate Anthropic / Google / OpenAI key is required.

Default models

The AiSettings table ships with these defaults, editable from /admin/settings:

RoleDefault model
Text generationclaude-sonnet-4.6
Cover image generationflux-2-pro

The gateway exposes models from Anthropic, Google, and OpenAI — the @ai-sdk/anthropic, @ai-sdk/google, and @ai-sdk/openai packages are all wired through @ai-sdk/gateway, so you can switch providers in the admin without touching env vars.

How article generation works

Article generation uses the Vercel AI SDK's generateObject with a strict Zod schema. The generator:

  1. Takes a user prompt, optional source URLs, tone, category, target keywords, and author name
  2. Builds a system prompt reflecting the selected tone and any custom AI settings
  3. Calls the configured text model through the gateway (default: claude-sonnet-4.6)
  4. Returns: 5 title options, selected title, subtitle, excerpt, AI summary, outline, tags, keywords, SEO title, SEO description, related topics, and the full markdown body
  5. Calls the configured image model (default: flux-2-pro) for the cover image and uploads it to R2
  6. Converts the markdown body to Portable Text for optional Sanity upload
  7. Calculates reading time (~200 words/minute)

Tip

Every request is saved to the ArticleGenerationRequest table with status tracking (PENDING, RUNNING, COMPLETED, FAILED). View and replay history at /admin/generation-history.

AI settings in the admin

SettingDefaultDescription
Text modelclaude-sonnet-4.6Gateway model used for article generation
Image modelflux-2-proGateway model used for cover images
Image size1536x1024Cover image dimensions (16:9)
Article system promptBuilt-in editorial promptOverride the default article prompt
Min word count500Target article length (configurable 200–5,000)
Default tonejournalisticprofessional, conversational, technical, journalistic, analytical

Safe usage notes

  • Never expose the gateway key client-side. All AI requests go through server-side routes; AI_GATEWAY_API_KEY is never sent to the browser.
  • Watch usage. Gateway spend is visible on your Vercel dashboard — set a spend cap once you move past the free credits.
  • Model availability. If you switch to a model that's not enabled on your Vercel account, enable it from the AI Gateway page first.