AI Provider Setup (Vercel AI Gateway)
Wire the Vercel AI Gateway for text and cover image generation.
Last updated:
Create an AI Gateway key
- Open your Vercel project → AI Gateway tab
- Click Create Key and give it a clear name
- Copy the key (starts with
vck_) - 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:
| Role | Default model |
|---|---|
| Text generation | claude-sonnet-4.6 |
| Cover image generation | flux-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:
- Takes a user prompt, optional source URLs, tone, category, target keywords, and author name
- Builds a system prompt reflecting the selected tone and any custom AI settings
- Calls the configured text model through the gateway (default:
claude-sonnet-4.6) - Returns: 5 title options, selected title, subtitle, excerpt, AI summary, outline, tags, keywords, SEO title, SEO description, related topics, and the full markdown body
- Calls the configured image model (default:
flux-2-pro) for the cover image and uploads it to R2 - Converts the markdown body to Portable Text for optional Sanity upload
- 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
| Setting | Default | Description |
|---|---|---|
| Text model | claude-sonnet-4.6 | Gateway model used for article generation |
| Image model | flux-2-pro | Gateway model used for cover images |
| Image size | 1536x1024 | Cover image dimensions (16:9) |
| Article system prompt | Built-in editorial prompt | Override the default article prompt |
| Min word count | 500 | Target article length (configurable 200–5,000) |
| Default tone | journalistic | professional, 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_KEYis 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.