Enhances user prompts on popular AI chat sites via a Chrome extension backed by a Cloudflare Worker. Secure by default with server-side system prompt injection, per-user rate limiting, and optional BYOK.
- One-click prompt enhancement across Claude, ChatGPT, Gemini, Grok, Perplexity
- Cloudflare Worker API (Hono) with strict CORS and JWT auth
- Durable Objects for daily rate limits, token gating, and usage aggregation
- Cloudflare Turnstile for human verification
- BYOK mode with client-side AES-GCM encryption for stored keys
- Install: Chrome Web Store
- Node.js 18+ and npm
- Cloudflare account and Wrangler CLI v4+
- Google Chrome 102+
- Clone and install
git clone <this-repo-url>
cd "AI Prompt Optimizer"
cd api && npm install- Authenticate and configure
npx wrangler login- In
api/wrangler.toml, setALLOWED_ORIGINSto include your extension id (e.g.,chrome-extension://<your-id>).
- Set required secrets
cd api
wrangler secret put OPENROUTER_API_KEY
wrangler secret put JWT_SECRET
wrangler secret put TURNSTILE_SECRET_KEY
wrangler secret put SYSTEM_PROMPT- Deploy the Worker
cd api
wrangler deploy- Load the Chrome extension
- Visit
chrome://extensions, toggle Developer mode, click “Load unpacked”, select the repo root. - Confirm host permissions include the Worker URL.
- Use
- Open a supported site, click the Enhance button to optimize your prompt.
- Open the popup to switch between Proxy and BYOK modes and view usage.
- Worker (API):
api/src/index.ts(Hono)- Endpoints
POST /api/token– verify Turnstile and issue JWTGET /api/config– return client config (rate limit, model, hosts)GET /api/ratelimit– peek current limitsGET /api/usage– per-user usage statsPOST /api/enhance– proxy enhancement using server keyPOST /api/enhance/byok– enhancement using user-provided keyGET /turnstile,GET /turnstile-embed– Turnstile flows
- Security
- CORS allowlist:
ALLOWED_ORIGINSwith the extension id - JWT auth for protected routes
- Server-side system prompt injection (never shipped to clients)
- Payload validation (zod), payload size caps, timeouts
- CORS allowlist:
- Endpoints
- Durable Objects
RateLimiter– per-user+IP daily allowance (default 100/day)TokenGate– IP-based anti-abuse backoff while fetching JWTUsageAggregator– daily/monthly/total counters per user
- Config via Wrangler
api/wrangler.tomldefines DO bindings and non-secret vars- Secrets are set with Wrangler and never committed
- Secrets (set via Wrangler; not in git)
OPENROUTER_API_KEY– upstream LLM key (proxy mode)JWT_SECRET– Worker JWT signing keyTURNSTILE_SECRET_KEY– Turnstile private keySYSTEM_PROMPT– stored as a secret or bound KV; injected server-side
- Non-secret vars (in
api/wrangler.toml)TURNSTILE_SITE_KEY(public),ALLOWED_ORIGINS,ALLOWED_HOSTS,RATE_LIMIT_PER_DAY,DEFAULT_MODEL, etc.
Set secrets
cd api
wrangler secret put OPENROUTER_API_KEY
wrangler secret put JWT_SECRET
wrangler secret put TURNSTILE_SECRET_KEY
wrangler secret put SYSTEM_PROMPTcd api
npm install
wrangler deploy- Load unpacked from the repo root:
manifest.json,service-worker.js,content.js,popup.html,popup.js - Default mode uses proxy (free daily quota). BYOK mode stores the user’s OpenRouter key encrypted with Web Crypto (AES-GCM) and optional passphrase.
- Open the extension popup
- Click “+ New”, enter a name, your OpenRouter key, and a passphrase, then Save
- Select the saved key, enter your passphrase, click Unlock
- Toggle mode to BYOK
- Keys and prompts are never persisted server-side beyond processing
- System prompt lives only on the server via secret/kv binding
- Rate limiting and gating enforced with Durable Objects at the edge
- Extension storage is encrypted (AES-GCM) and supports passphrase mode
- Root (extension): manifest and UI (
manifest.json,service-worker.js,content.js,popup.html,popup.js,icons/,config/,services/,utils/) api/(Cloudflare Worker): Hono app, Durable Objects, Wrangler config
- Do not commit secrets; use
wrangler secret putfor all sensitive values - Recommended: run
wrangler dev --remoteinapi/for parity with edge runtime - Load the extension as “unpacked” during development and reload after changes
- MIT License. Not affiliated with OpenAI, Anthropic, Google, X, or any AI provider