Cloudflare Worker backend for /api/consult.
- Accepts public consult requests from the portfolio consult page.
- Attempts Workers AI inference (
@cf/meta/llama-3.1-8b-instruct). - Falls back to deterministic capability mapping if AI fails or times out.
- Logs full request records to D1 (
consult_logs).
POST /api/consult
Request JSON:
{
"challenge": "Need help designing a multi-agent content pipeline...",
"industry": "saas",
"page": "/portfolio/consult/",
"requestId": "uuid"
}Success JSON:
{
"ok": true,
"mode": "ai",
"analysisHtml": "<p>...</p>",
"analysisText": "Plain text...",
"requestId": "uuid",
"durationMs": 482
}Fallback JSON (mode: "fallback"):
{
"ok": true,
"mode": "fallback",
"analysisHtml": "<p>...</p>",
"analysisText": "Plain text...",
"requestId": "uuid",
"durationMs": 121,
"note": "Workers AI is unavailable right now. Showing deterministic capability mapping."
}Error JSON:
{
"ok": false,
"code": "BAD_INPUT",
"message": "Challenge must be between 20 and 4000 characters.",
"requestId": "uuid"
}- Authenticate Wrangler:
npx wrangler whoami- Create D1 database:
npx wrangler d1 create portfolio-consult-logs-
Copy returned
database_idintoworkers/consult-api/wrangler.jsonc. -
Apply migrations:
npx wrangler d1 migrations apply portfolio-consult-logs --config workers/consult-api/wrangler.jsonc --remote- Set secrets:
npx wrangler secret put LOG_HASH_SALT --config workers/consult-api/wrangler.jsonc- Deploy:
npx wrangler deploy --config workers/consult-api/wrangler.jsonc- Set frontend API base in deployment env:
PUBLIC_CONSULT_API_BASE=https://<your-worker-subdomain>.workers.dev