Skip to content

Worker settings

Set local values in worker/.dev.vars (copy from .dev.vars.example); production values live in wrangler.toml [vars] or as encrypted secrets.

VariableRequiredDefaultDescription
ANTHROPIC_API_KEYYesAnthropic API key. Always set as a secret: npx wrangler secret put ANTHROPIC_API_KEY
ALLOWED_ORIGINYeshttp://localhost:5173Origin(s) allowed by CORS. Accepts a comma-separated list, e.g. https://a.example,https://b.example. Any http://localhost:* origin is always allowed for development
CLAUDE_MODELNoclaude-haiku-4-5-20251001Claude model used for replies
MAX_TOKENSNo1024Max response tokens
RATE_LIMIT_MINUTENo10Requests per minute per IP
RATE_LIMIT_HOURNo50Requests per hour per IP
BindingRequiredPurpose
RATE_LIMIT (KV)YesPer-IP rate-limit counters. Create with npx wrangler kv namespace create RATE_LIMIT
ANALYTICS_DB (D1)NoMetadata-only analytics events. When absent, the chat endpoint works normally and skips recording

See Deploy the worker for the exact wrangler commands.

The bot’s personality, knowledge, and guardrails live in worker/src/system-prompt.ts. The repo ships a generic template; edit it to describe your business, services, pricing, and FAQ. The prompt also includes behavioral rules (response length, formatting, prompt-injection protection, when to recommend a contact form).

Redeploy the worker after editing:

Terminal window
cd worker
npx wrangler deploy

The worker validates every request before calling Claude:

  • messages is required and non-empty
  • At most 100 messages per request
  • Each message’s content is truncated to 2,000 characters
  • Roles must be user or assistant

Violations return 400 with code VALIDATION_ERROR — see the REST API reference.