Skip to content

OpenAI Integration

Honeycomb uses the OpenAI API for AI-powered content features in the site builder and AI docs apps. All calls are server-side only — the API key never reaches the browser.

The OpenAI client is a lazy singleton in src/lib/modules/sitebuilder/services/ai.service.ts:

import OpenAI from "openai";
import { OPENAI_API_KEY } from "$env/static/private";
let _openai: OpenAI | null = null;
function openai(): OpenAI {
if (!_openai) {
_openai = new OpenAI({ apiKey: OPENAI_API_KEY });
}
return _openai;
}

A separate Supabase service-role client writes usage records to the ext_builder.ai_generations table.

Text Generation

Generates website copy using gpt-4o-mini with a system prompt tailored for conversion-focused copywriting.

Text Modification

Simplify, shorten, lengthen, fix spelling, change tone, or translate existing text.

Image Generation

Creates images via DALL-E 3 with configurable size and style (vivid or natural).

Usage Tracking

Every generation is logged with token count, model, prompt, and response for billing and audit.

export async function generateText(
userId: string,
prompt: string,
context?: string,
): Promise<{ text: string; tokensUsed: number }>
  • Model: gpt-4o-mini
  • Temperature: 1
  • Max tokens: 1024
  • System prompt: Instructs the model to act as a professional copywriter producing clean, conversion-focused copy without markdown formatting.
  • An optional context parameter injects background about the website before the user’s prompt.
export async function modifyText(
userId: string,
text: string,
action: AiModifyAction,
params?: { tone?: AiTone; language?: string },
): Promise<{ text: string; tokensUsed: number }>

Supported actions:

ActionDescription
simplifyMake text easier to understand
shortenCondense while keeping the key message
lengthenExpand with more detail
fix_spellingCorrect spelling, grammar, and punctuation
change_toneRewrite in a specified tone (requires params.tone)
translateTranslate to a target language (requires params.language)
  • Model: gpt-4o-mini
  • Temperature: 0.7 (lower than generation for more faithful rewrites)
export async function generateImage(
userId: string,
prompt: string,
size?: "1024x1024" | "1792x1024" | "1024x1792",
style?: "vivid" | "natural",
): Promise<{ url: string }>
  • Model: DALL-E 3
  • Default size: 1024x1024
  • Default style: vivid

The returned URL is a temporary Stripe-hosted image. The caller is responsible for downloading and storing it in Supabase Storage if persistence is needed.

Every call writes a row to ext_builder.ai_generations:

ColumnDescription
user_idThe authenticated user
typegenerate_text, modify_text, generate_image, or modify_image
promptThe input prompt or action description
responseGenerated text or image URL
tokens_usedTotal tokens consumed (1 for image generations)
modelModel identifier (gpt-4o-mini, dall-e-3)
// Get paginated generation history
await listAiGenerations(userId, { limit: 25, offset: 0 });
// Get current month stats
await getUsageStats(userId);
// Returns: { text_tokens_used, image_count, period_start }

The AI Docs app (src/lib/apps/aidocs) supports multiple model providers. The model constants are defined in src/lib/apps/aidocs/constants.ts:

export const AI_MODELS = [
"gpt-4o",
"gpt-4o-mini",
"gpt-4-turbo",
"gpt-3.5-turbo",
"claude-sonnet-4-20250514",
"claude-haiku-4-5-20251001",
"gemini-2.5-pro",
"gemini-2.5-flash",
] as const;
export const DEFAULT_MODEL = "gpt-4o" as const;
FilePurpose
src/lib/modules/sitebuilder/services/ai.service.tsOpenAI client, text/image generation, usage tracking
src/lib/apps/aidocs/constants.tsMulti-provider model list and defaults