OpenAI Setup
How to configure OpenAI for AI-powered article and image generation.
Last updated:
OpenAI setup
- Go to platform.openai.com/api-keys
- Click Create new secret key
- Copy the key (starts with
sk-proj-) - 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
| Model | Role |
|---|---|
gpt-5-mini (default) | Main article generation via the streaming API route |
gpt-5 | High-quality generation for long-form content |
gpt-5-nano | Fastest and most cost-effective option |
gpt-4o | Structured output generation (used by utility functions) |
gpt-4o-mini | Lightweight tasks — title regeneration, SEO metadata, AI summaries |
gpt-4-turbo | Legacy high-quality model |
Image models
| Model | Role | Sizes |
|---|---|---|
gpt-image-1 (default) | AI cover image generation | 1536×1024, 1024×1024, 1792×1024 |
dall-e-3 | Alternative image model | 1024×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:
- 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 (default:
gpt-5-mini) to generate content - 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
- Converts the markdown body to Portable Text for optional Sanity upload
- 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:
| Setting | Default | Description |
|---|---|---|
| Text model | gpt-5-mini | OpenAI model used for article generation (6 models available) |
| Image model | gpt-image-1 | OpenAI model used for cover image generation (gpt-image-1 or dall-e-3) |
| Image size | 1536x1024 | Cover image dimensions (16:9 format) |
| Article system prompt | Built-in editorial prompt | Custom system prompt for article generation — overrides the default |
| Min word count | 500 | Target article length in words (configurable from 200 to 5,000) |
| Default tone | journalistic | Default 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_KEYis 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.