Shield public unauthenticated AI forms from bot abuse
Keep interactive landing-page demos and public lead widgets safe from scripted prompt drain using origin checks, payload caps, and Turnstile tokens.
Checklist to harden public AI form endpoints
- 01
Verify bot-challenge tokens
Validate Cloudflare Turnstile or captcha tokens server-side inside APIkit before model execution.
- 02
Lock prompt intent tightly
Use strict schemas and tiny input length caps so attackers cannot repurpose your widget as free ChatGPT.
- 03
Apply harsh anonymous IP limits
Cap unauthenticated IPs to a handful of calls per hour while logged-in users get real quotas.
- 04
Enable edge response caching
Serve preset sample demos from zero-cost edge cache so casual clicks never touch model quotas.
How it works in practice
Public Widget Hardening Stack
1. Turnstile Token Verification -> required 2. Origin Lock -> https://acme.com only 3. IP Sliding Limit -> 5 runs / hour 4. Input Cap -> max 280 chars | Output -> max 120 tokens
Blocked Bot Probe vs Legitimate Visitor
Scripted curl spam -> 403 {"error":"missing_turnstile_token"} Verified browser -> 200 OK (served within 5/hr budget)
Marketing widgets stay interactive for genuine prospects while automated scripts fail at the edge at zero token cost.
Common questions
How do you stop someone curling a public widget endpoint directly?
Requiring a one-time verified challenge token alongside strict origin and IP limits blocks automated terminal scripts.
Can attackers still hijack a capped public prompt for unrelated essays?
Combining a tight 280-character input limit, strict JSON schema, and low max_tokens prevents off-task general chat abuse.
Does Turnstile verification require us to run a backend endpoint?
No. APIkit verifies the challenge token directly at the gateway before running your prompt.
Related tasks in this category
See all in API Key Auth, Scopes & Quotas-
Issue scoped API keys per customer and environment
Generate prefixed keys restricted to specific endpoints, read-only routes, or workspaces—no custom auth database required.
-
Meter and cap monthly token quotas per tenant
Track exact prompt and completion token usage per workspace, warn at 80%, and enforce clean monthly caps without building Stripe metering pipelines.
-
Rotate API keys smoothly with overlapping grace windows
Issue replacement API keys with a configurable 24-hour or 7-day overlap window so mobile workers and cron jobs migrate without outages.
-
Verify end-user JWT claims directly at your AI endpoint
Let web or mobile apps pass Auth0, Clerk, or Supabase JWTs straight to APIkit—verifying signatures and claims without a proxy server.
-
Lock internal AI endpoints to approved IP and CIDR ranges
Ensure B2B partner integrations and internal admin pipelines only accept traffic from static VPN, VPC NAT, or enterprise IP blocks.
-
Configure exact CORS origin policies for browser clients
Allow your production domains and preview deployments to call endpoints cleanly while blocking unauthorized third-party sites.