OpenAI Setup

How to configure OpenAI for AI-powered article and image generation.

Last updated:

OpenAI setup

  1. Go to platform.openai.com/api-keys
  2. Click Create new secret key
  3. Copy the key (starts with sk-proj-)
  4. Add it to your env file:
.env.local
OPENAI_API_KEY=sk-proj-...

Models used

BloggFast supports multiple OpenAI models, selectable from the admin AI settings at /admin/settings.

Text models

ModelRole
gpt-5-mini (default)Main article generation via the streaming API route
gpt-5High-quality generation for long-form content
gpt-5-nanoFastest and most cost-effective option
gpt-4oStructured output generation (used by utility functions)
gpt-4o-miniLightweight tasks — title regeneration, SEO metadata, AI summaries
gpt-4-turboLegacy high-quality model

Image models

ModelRoleSizes
gpt-image-1 (default)AI cover image generation1536×1024, 1024×1024, 1792×1024
dall-e-3Alternative image model1024×1024, 1792×1024

How article generation works

Article generation uses the Vercel AI SDK's generateObject function with a strict Zod schema for structured output. 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 (default: gpt-5-mini) to generate content
  4. Returns: 5 title options, selected title, subtitle, excerpt, AI summary, article outline, tags, keywords, SEO title, SEO description, related topics, and the full markdown body
  5. Converts the markdown body to Portable Text for optional Sanity upload
  6. Calculates reading time (~200 words/minute)

Tip

The generation request is saved to the ArticleGenerationRequest table in Postgres. You can view and manage all generation history at /admin/generation-history.

AI settings in the admin

BloggFast stores AI configuration in the AiSettings database table (singleton). Admin users can customize these at /admin/settings:

SettingDefaultDescription
Text modelgpt-5-miniOpenAI model used for article generation (6 models available)
Image modelgpt-image-1OpenAI model used for cover image generation (gpt-image-1 or dall-e-3)
Image size1536x1024Cover image dimensions (16:9 format)
Article system promptBuilt-in editorial promptCustom system prompt for article generation — overrides the default
Min word count500Target article length in words (configurable from 200 to 5,000)
Default tonejournalisticDefault writing tone (professional, conversational, technical, journalistic, analytical)

Safe usage notes

  • Never expose API keys client-side. All AI requests in BloggFast go through server-side API routes — the OPENAI_API_KEY is never sent to the browser.
  • Set usage limits in your OpenAI dashboard to prevent unexpected charges. Navigate to Usage → Limits in the OpenAI platform.
  • Rate limits apply. Free/trial API keys have strict rate limits. Upgrade to a paid OpenAI account for reliable generation.
  • gpt-image-1 access. Image generation with gpt-image-1 requires a paid OpenAI account with image generation enabled. Check your account's model access at platform.openai.com.