Skip to main content

AI Config

OpenAI or Anthropic for auto-generating descriptions.

File: config/ai.config.ts

When AI is on, users get "Generate with AI" buttons in the submit flow — the LLM writes descriptions, suggests categories, and fills SEO metadata from a URL.

Two switches to flip

You need both ai: true in features.config.ts and a valid AI_API_KEY. Either missing → AI silently skips.

Supported providers

ProviderWhere to get a key
OpenAIplatform.openai.com → API keys
Anthropicconsole.anthropic.com → API keys

OpenAI API keys page

Anthropic Console API keys

Setup

1. Turn on the feature flag

config/features.config.ts
export const featuresConfig = {
  // ...
  ai: true,
};

2. Add env vars

.env.local
AI_PROVIDER=openai          # or 'anthropic'
AI_MODEL=gpt-4o-mini        # or 'claude-haiku-4-5' etc.
AI_API_KEY=sk-...

Restart the dev server.

3. Verify

Go to /submit → fill in a project URL → click "Generate description with AI". If nothing happens, check the dev console / network tab for errors.

The config file

config/ai.config.ts
export const aiConfig = {
  provider: (process.env.AI_PROVIDER as 'openai' | 'anthropic') || 'openai',
  model: process.env.AI_MODEL || 'gpt-4o-mini',
  apiKey: process.env.AI_API_KEY || '',
  maxTokens: 1000,
  temperature: 0.7,
};
FieldDefaultWhat it does
provideropenaiProvider. Must match your key.
modelgpt-4o-miniModel ID. See provider's docs for available models.
apiKeyPulled from AI_API_KEY.
maxTokens1000Max response length.
temperature0.70 = deterministic, 1 = creative. Good middle ground for descriptions.

For directory descriptions (short, factual), cheap fast models win:

ProviderModelInput / Output cost
OpenAIgpt-4o-minicheapest GPT-4-class
Anthropicclaude-haiku-4-5cheap and fast
OpenAIgpt-4obetter quality, more expensive
Anthropicclaude-sonnet-4-5best quality Anthropic

Start with the cheap one. Only upgrade if outputs are noticeably worse.

Cost control

  • Each description generation is ~300-500 tokens → fractions of a cent per request.
  • Rate-limit AI endpoints in lib/rate-limit.ts to prevent abuse.
  • Consider caching generated descriptions by URL so re-submissions don't re-pay.

See also