Skip to content

feat(ai): free Groq AI analysis via Cloudflare Worker proxy#306

Merged
AugustoL merged 2 commits intoopenscan-explorer:devfrom
AugustoL:feat/ai-cloudflare-worker
Mar 12, 2026
Merged

feat(ai): free Groq AI analysis via Cloudflare Worker proxy#306
AugustoL merged 2 commits intoopenscan-explorer:devfrom
AugustoL:feat/ai-cloudflare-worker

Conversation

@AugustoL
Copy link
Collaborator

Description

Add a free AI analysis tier powered by Groq through a Cloudflare Worker proxy. Users can now use AI analysis out of the box without configuring their own API key.

Related Issue

Closes #269

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Performance improvement
  • Other (please describe):

Changes Made

Cloudflare Worker (worker/)

  • Hono app with POST /ai/analyze endpoint
  • CORS origin allowlist with wildcard suffix support (for Netlify preview deploys)
  • Per-IP sliding window rate limiting (10 req/min)
  • Payload validation: known analysis types, 2 messages, 32KB body limit
  • Forwards requests to Groq API with server-side GROQ_API_KEY secret

Frontend Integration

  • Added openscan-groq to AIProvider type
  • Added OpenScan Groq provider config (keyless, first in priority order)
  • Added callOpenScanProxy() method in AIService — posts to worker with { type, messages }, no Authorization header
  • Updated resolveProvider() in useAIAnalysis to return openscan-groq without checking for an API key
  • Filtered openscan-groq from Settings API key UI (no key to configure)
  • Added REACT_APP_OPENSCAN_GROQ_AI_URL env var in Vite config

Allowed Origins

  • http://openscan.eth.link
  • https://openscan-explorer.github.io
  • https://openscan.netlify.app
  • *.openscan.netlify.app (preview deploys like https://pr-123--openscan.netlify.app)

Checklist

  • I have run npm run format:fix and npm run lint:fix
  • I have run npm run typecheck with no errors
  • I have run tests with npm run test:run
  • I have tested my changes locally
  • I have updated documentation if needed
  • My code follows the project's architecture patterns

Additional Notes

  • The worker is already deployed at https://openscan-groq-ai-proxy.openscan.workers.dev with the Groq API key configured as a secret
  • If a user configures their own API key in Settings, that provider takes priority over openscan-groq
  • Rate limit is in-memory (resets on worker cold start) — sufficient for lightweight protection; Durable Objects can be used later for stricter limits

Add openscan-groq provider that proxies AI requests through a
Cloudflare Worker, allowing users to use AI analysis without
configuring their own API key.

Worker: Hono app with CORS origin allowlist, per-IP rate limiting
(10 req/min), payload validation, and Groq API forwarding.

Frontend: new openscan-groq provider (first in priority order),
callOpenScanProxy method in AIService, keyless resolution in
useAIAnalysis hook, filtered from Settings API key UI.

Closes openscan-explorer#269
@github-actions
Copy link

github-actions bot commented Mar 12, 2026

🚀 Preview: https://pr-306--openscan.netlify.app
📝 Commit: 3780c541d1f7302ffe3ba770549f9694f394939d

Netlify previews use -- separator (pr-306--openscan.netlify.app),
not subdomain dots. Update wildcard pattern and matching logic.
@AugustoL AugustoL requested a review from josealoha666 March 12, 2026 18:12
Copy link
Collaborator

@josealoha666 josealoha666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff locally. The keyless provider wiring looks coherent, the worker-side CORS/rate-limit/validation guards make sense, and typecheck/test/build passed for me. Nice fix on the Netlify preview origin matching too.

@AugustoL AugustoL merged commit 2c03a71 into openscan-explorer:dev Mar 12, 2026
4 of 7 checks passed
Copy link
Collaborator

@josealoha666 josealoha666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review: I skimmed the diff and did not find a clear blocker. Leaving a comment-only review for now.

Copy link
Collaborator

@josealoha666 josealoha666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the current head and I do not see an obvious blocking issue from the diff/API view. If CI is green, this looks fine from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants