Deploy the worker
This content is for v1.x. Switch to the latest version for up-to-date documentation.
One-time setup
Section titled “One-time setup”cd workerpnpm installnpx wrangler loginRate-limit KV namespace
Section titled “Rate-limit KV namespace”npx wrangler kv namespace create RATE_LIMITCopy the generated id into worker/wrangler.toml:
[[kv_namespaces]]binding = "RATE_LIMIT"id = "your-id-here"preview_id = "your-preview-id-here"Secrets and deploy
Section titled “Secrets and deploy”npx wrangler secret put ANTHROPIC_API_KEYnpx wrangler deploySet ALLOWED_ORIGIN to the origin(s) that may call the worker — in
wrangler.toml [vars] or the dashboard (Workers → Settings → Variables).
Comma-separate multiple origins:
ALLOWED_ORIGIN = https://your-site.example,https://docs.your-site.examplehttp://localhost:* is always allowed for development.
Analytics with D1 (optional)
Section titled “Analytics with D1 (optional)”The chat endpoint records metadata-only events (timing, token counts, status,
error codes — never message contents) when the ANALYTICS_DB binding exists.
Without the binding the endpoint works normally.
npx wrangler d1 create claudius-analytics# paste database_id into wrangler.toml:# [[d1_databases]]# binding = "ANALYTICS_DB"# database_name = "claudius-analytics"# database_id = "your-id-here"
# run the migration (production and local)npx wrangler d1 execute claudius-analytics --remote --file=./migrations/0001_create_events.sqlnpx wrangler d1 execute claudius-analytics --local --file=./migrations/0001_create_events.sqlTuning
Section titled “Tuning”Optional [vars] in wrangler.toml: CLAUDE_MODEL, MAX_TOKENS,
RATE_LIMIT_MINUTE, RATE_LIMIT_HOUR — see
Worker settings for defaults.