Description
Summary Overview I have a Next.js website with a newsletter signup form that currently submits directly from the browser to HubSpot's Forms v3 endpoint. I want to add a lightweight LLM-based spam filter that inspects each submission *before* it reaches HubSpot, and silently rejects (or flags) anything that looks like spam/bot/junk input. Current setup - Framework: Next.js (App Router, TypeScript, React client component) - The form component (`NewsletterForm.tsx`) POSTs directly to `https://api.hsforms.com/submissions/v3/integration/submit/[portalId]/[formGuid]` - Fields collected: `firstname`, `lastname` (optional), `jobtitle`, `email` - Portal ID and Form GUID are public form identifiers (no secrets today) What I want you to build 1. Create a server-side API route in the Next.js app (e.g. `app/api/subscribe/route.ts`) that: - Receives the form fields from the client - Runs an LLM spam/quality check (e.g. OpenAI or similar) to classify the submission as legit vs. spam — checking for gibberish names, fake/disposable emails, nonsense job titles, injection attempts, etc. - If legit → forwards the submission to HubSpot (server-side) - If spam → rejects gracefully with a generic message (no HubSpot write) 2. Update the existing `NewsletterForm.tsx` to POST to the new internal API route instead of calling HubSpot directly. 3. Keep the LLM API key server-side only (use an environment variable — never expose it to the client). 4. Preserve the existing UX: loading / success / error states should still work. Deliverables - Working API route with the LLM spam check + HubSpot forwarding - Updated form component - Brief note on which env vars to set (`OPENAI_API_KEY`, etc.) and how to configure them - Clean, typed TypeScript that matches the existing code style Nice to have (optional) - Basic rate limiting / honeypot field as a cheap first line of defense before the LLM call - Configurable spam threshold or a logged "reason" when something is rejected Requirements to apply - Strong Next.js App Router + TypeScript experience - Experience calling an LLM API (OpenAI or equivalent) from a server route - Familiarity with HubSpot Forms API is a plus To apply, please briefly answer: 1. Which LLM/provider would you use and roughly what would it cost per submission? 2. How would you handle the case where the LLM API is slow or down — do you fail open (let it through) or fail closed (block it)? 3. Have you integrated with HubSpot Forms before? (yes/no is fine)