Secure AI Calls via Supabase Edge Function
The ai-proxy Edge Function proxies all OpenRouter API calls server-side.
Your API key is stored as a Deno secret and never sent to the browser —
protecting against key exposure in DevTools, localStorage, or network logs.
Browser
chat.html / index.html
only (no API key)
Supabase
Edge Function
ai-proxy
(Deno secret — server only)
server-side
OpenRouter
openrouter.ai
authenticated request
The browser only ever authenticates with your Supabase anon key (which is already public by design).
The OpenRouter API key is read from Deno.env.get('OPENROUTER_API_KEY') — completely server-side.
Install Supabase CLI (if not already installed)
You need the Supabase CLI to deploy Edge Functions and set secrets.
Login and link your project
Connect the CLI to your Supabase project. You'll need your project reference ID from the Supabase dashboard URL.
Set your OpenRouter API key as a Supabase secret
This stores the key securely on Supabase's servers — it's never in your code or database.
openrouter_api_key value from your platform_settings table in Supabase — it's no longer needed there. The key now lives only in Deno secrets.Deploy the Edge Function
The function file already exists at supabase/functions/ai-proxy/index.ts in your project.
--no-verify-jwt flag does NOT make the function public. The browser still sends the Supabase anon key as Authorization: Bearer <anon-key>. The flag just means the function handles its own auth rather than requiring a full Supabase JWT user session.Verify deployment
Check the function is live by listing deployed functions:
Or test it manually with curl:
Test in the app
No code changes needed — all 3 features automatically use the proxy once it's deployed:
- Agent Builder → AI Context — open any flow → click 🤖 AI Context in topbar → click Regenerate
- Chat runtime → AI Call node — run any flow that has an AI Call node in the chatbot
- API Collection → Auto-describe — open any API collection → select a request → click Auto-describe
platform_settings.openrouter_model and fetched by the proxy caller.
The model name is safe to send from the browser — only the API key is secret.
Error: "OpenRouter API key not configured"
The Edge Function can't find the secret. Re-run:
Error: "AI proxy not configured — SUPABASE_URL missing"
The browser can't find the proxy URL. Check js/sb-config.js:
CORS error in browser console
The Edge Function already includes CORS headers for all origins. If you see CORS errors, check that the function deployed successfully: