rhocfsandbox.com

demo: workers ai + ai gateway chat

a small chat bot backed by llama-3.3-70b-instruct-fp8-fast on workers ai, routed through cloudflare ai gateway for rate limiting and observability. the model has no internet access, so it won't know today's weather or news. ask it about web tech, cloudflare products, networking, etc.

limits (to prevent abuse of my neuron budget): 3 requests per hour per ip (ai gateway). turnstile challenge required. 500 char input max, 200 token output max. off-topic questions get a polite decline.

# try one of these

# ask

waiting…

# how it works

  1. page function /api/chat verifies turnstile server-side
  2. truncates prompt to 500 chars, adds a system prompt (topic guardrail)
  3. calls env.AI.run(...) with the AI Gateway option set to site-ai-gateway
  4. ai gateway enforces its own rate limit (3/hour/ip, sliding window)
  5. on 429, we surface a friendly message with a suggested retry time

# config

model@cf/meta/llama-3.3-70b-instruct-fp8-fast
ai gatewaysite-ai-gateway (see /ai-gateway)
rate limit3 req / 3600s / ip, sliding
max tokens200 output, 500 char input
bindingsAI (workers ai), TURNSTILE_SECRET_KEY