Open the Supabase SQL editor for the whichmodel project and run:
migrations/001_api_keys.sql
This creates:
api_keystable (key_hash, plan, monthly_limit, revoked_at, stripe fields)usage_monthlytable (key_id, month, request_count)increment_usage(p_key_id, p_month)RPC function (atomic counter upsert)- RLS enabled on both tables (service role bypasses RLS)
wrangler kv namespace create API_KEYSCopy the printed id and replace __API_KEYS_NAMESPACE_ID__ in wrangler.toml.
For the preview/local environment, also run:
wrangler kv namespace create API_KEYS --previewAnd add a preview_id line under [[kv_namespaces]] in wrangler.toml.
wrangler secret put SUPABASE_SERVICE_ROLE_KEYPaste the service role key from your Supabase project settings when prompted.
npm run deploy
# or: wrangler deployTest an unauthenticated request (should still work, free tier):
curl https://whichmodel-mcp.<your-subdomain>.workers.dev/healthTest a revoked/invalid key (should return 401):
curl -H "Authorization: Bearer wm_live_invalidkey" https://whichmodel-mcp.<your-subdomain>.workers.dev/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'Insert a test key in Supabase and verify the full auth flow (KV cache, usage count).