Browser integration
The widget reads a public Worker base URL from data-groot-api-base, sends a short conversation over HTTPS, and renders safe answer text and validated links.
← Back to hands-on labs
AI ASSISTANT · CLOUDFLARE · OPENAI
A reproducible implementation that connects a GitHub Pages portfolio to an OpenAI-backed assistant through a Cloudflare Worker, with official-source grounding, D1-backed quotas, secret management, and operational validation.
Visitor browser
↓ HTTPS fetch
GitHub Pages portfolio + Ask Groot widget
↓ POST /api/chat
Cloudflare Worker
↙ ↓ ↘
D1 quota OpenAI API Origin and input validation
↓
official-documentation web search
↓
short answer + source links + quota metadata
The static page owns the user interface. The Worker is the server-side boundary: it keeps the OpenAI key out of the browser, applies request controls, calls the model, and returns a small JSON contract.
The widget reads a public Worker base URL from data-groot-api-base, sends a short conversation over HTTPS, and renders safe answer text and validated links.
The Worker handles CORS, body-size limits, message validation, bounded history, timeouts, no-store responses, and an explicit health endpoint.
The Responses API uses web search restricted to approved official documentation domains; returned sources are checked again before they reach the browser.
Cloudflare D1 stores a salted IP hash and rolling 24-hour count. Wrangler deploys the Worker, migrations, and secrets while the public page stays static.
OPTIONS /api/chat
↓
CORS preflight response
GET /api/health
↓
Worker + D1 binding check
POST /api/chat
↓
Validate origin, size, history and message
↓
Read rolling quota from D1
↓
Call OpenAI Responses API with web search
↓
Validate answer and official source URLs
↓
Return answer, sources and quota status
wrangler login --device wrangler d1 create groot-usage wrangler d1 migrations apply groot-usage --remote wrangler secret put OPENAI_API_KEY --name groot-api wrangler secret put RATE_LIMIT_SALT --name groot-api wrangler deploy
Deployment was verified with health and chat requests using the live portfolio origin. The Worker endpoint is https://groot-api.support-dupatane.workers.dev. The complete runbook, source, migration, troubleshooting, operations, and rollback notes are kept in the private companion repository groot-openai-api-chatbot.