openrouter
OpenRouter keys in your Bolt or Lovable app: why sk-or-v1- is a secret
Why OpenRouter sk-or-v1- keys are bearer secrets (not publishable), how to check in two minutes, and copy-paste Next.js and Supabase Edge proxies with credit limits—then re-scan with the free grader.
Paste your production URL into the free Vibe Code Health grader for a Semrush-style score on secrets, headers, TLS, and common leaks—then come back to this guide for the fixes.
You asked Bolt, Lovable, or Cursor for “a chat app that can switch between GPT and Claude.” The model suggested OpenRouter—one API, many models—and pasted something that looks like sk-or-v1- plus a long hex string into a React file or a VITE_ env. The demo answered. You shared the link.
Here is the problem: an OpenRouter key is a full secret, not a publishable client token. Anyone who opens DevTools or downloads your JavaScript can spend your credits (and any auto top-ups) until you delete the key.
This guide is only about OpenRouter sk-or-v1- keys leaked in vibe-coded frontends. It is not the general frontend-key tour (API keys in Bolt, v0, and Lovable), not Discord/Slack webhooks (webhook passwords), and not Supabase anon vs service_role (Supabase keys).
Paste your live URL into Vibe Code Health—a public OpenRouter key forces an F, same as a live OpenAI or Stripe secret.
What an OpenRouter key actually is
OpenRouter’s authentication docs define an API key as sk-or-v1- followed by 64 lowercase hexadecimal characters (73 characters total). You send it as Authorization: Bearer … on requests to their API (OpenRouter: API Authentication).
That is the same shape as other LLM vendor secrets: possession of the string is authorization. There is no separate “publishable” OpenRouter key for browsers. OpenRouter also recommends a credit limit on every key, because a key with no limit can drain your balance—including auto top-ups—if it leaks (same auth guide).
If a key is exposed, their guidance is blunt: delete it and create a new one; do not leave it in public repos or client code (OpenRouter: If your key has been exposed).
OWASP’s secrets-management cheat sheet makes the same product rule in vendor-neutral language: secrets belong in a secure store or server environment, not in shipped client assets (OWASP Secrets Management Cheat Sheet).
Why vibe builders put sk-or-v1- in the browser
AI builders optimize for a working chat in one prompt:
- You create a key on OpenRouter’s API keys page.
- The model writes
fetch("https://openrouter.ai/api/v1/chat/completions", { headers: { Authorization: \Bearer ${key}` } })` in a client component. - Vite or Next inlines it via
import.meta.env.VITE_OPENROUTER_API_KEYorNEXT_PUBLIC_OPENROUTER_API_KEY. - Launch traffic and scrapers pull the bundle; the key is already burned.
Minification does not encrypt strings. If sk-or-v1- appears in a .js file, assume it is copied.
The anti-pattern
// ❌ Dangerous — ships to every visitor
const key = import.meta.env.VITE_OPENROUTER_API_KEY;
await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${key}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: prompt }],
}),
});
Anything prefixed for client exposure (VITE_, NEXT_PUBLIC_, many “public env” toggles in Lovable/Bolt/v0) is visible on purpose.
Two-minute check
- Open your production site → DevTools → Network → send a chat message.
- If the browser talks to
openrouter.aiwith anAuthorization: Bearer sk-or-v1-…header, the key is public. - Or search Sources / “Search in all files” for
sk-or-v1-oropenrouter.ai. - Paste the hostname into Vibe Code Health. A finding titled OpenRouter API key is public means the secret is already downloadable.
If you find one: treat it as burned. Delete it in the OpenRouter dashboard, create a replacement, and put a credit limit on the new key before you wire anything else (OpenRouter security settings).
Fix: browser → your backend → OpenRouter
The safe shape matches every other LLM vendor:
- Delete the leaked key; create a new one with a spend limit.
- Store it as server-only
OPENROUTER_API_KEY(no public prefix). - Expose a small API route or edge function your UI calls.
- Rate-limit and auth that route so strangers cannot turn your proxy into a free OpenRouter relay on your bill.
Next.js (App Router)
// app/api/chat/route.ts — server only
export async function POST(req: Request) {
const { messages } = await req.json();
if (!Array.isArray(messages) || messages.length === 0) {
return Response.json({ error: "Bad request" }, { status: 400 });
}
// TODO: session check + rate limit by user or IP
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
"Content-Type": "application/json",
"HTTP-Referer": process.env.NEXT_PUBLIC_SITE_URL ?? "https://yourdomain.com",
"X-Title": "Your App",
},
body: JSON.stringify({
model: "openai/gpt-4o-mini",
messages,
}),
});
return new Response(res.body, {
headers: { "Content-Type": "application/json" },
});
}
// ✅ Client — no OpenRouter key anywhere
await fetch("/api/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ messages }),
});
On Vercel, set OPENROUTER_API_KEY under Project → Settings → Environment Variables and leave it sensitive / non-public.
Supabase Edge Function (common with Lovable)
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
Deno.serve(async (req) => {
const { messages } = await req.json();
const key = Deno.env.get("OPENROUTER_API_KEY");
if (!key) return new Response("missing secret", { status: 500 });
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${key}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ model: "openai/gpt-4o-mini", messages }),
});
return new Response(res.body, {
headers: { "Content-Type": "application/json" },
});
});
Set the secret with supabase secrets set, not in the Vite env file. Call the function from the browser only after you add auth or a captcha—otherwise people can still spend through your function (better than owning your raw key, still worth rate-limiting).
Lovable / Bolt / v0 checklist
- Delete
sk-or-v1-from chat-generated files and any “public” env toggle. - Add a backend/cloud function the builder supports (or export to GitHub and add a Vercel/Netlify/Supabase function).
- Put the new key only in private secrets; set a credit limit in OpenRouter.
- Redeploy; confirm Network no longer shows
openrouter.aiBearer tokens from the client. - Re-scan on Vibe Code Health and skim related notes on /learn.
OpenRouter vs OpenAI vs Groq (same rule, different prefix)
| Vendor | Typical secret prefix | Browser OK? |
|---|---|---|
| OpenRouter | sk-or-v1- + 64 hex | Never |
| OpenAI | sk-proj-, sk-svcacct-, legacy sk- | Never |
| Anthropic | sk-ant- | Never |
| Groq | gsk_ | Never |
If your AI “fixed” a leaked OpenAI key by switching the URL to OpenRouter but kept the key in the client, you only changed the billing vendor—not the vulnerability.
What “fixed” looks like
| Signal | Still broken | Fixed |
|---|---|---|
Bundle search for sk-or-v1- | Hit | No hit |
| Network on chat send | Browser → openrouter.ai with Bearer | Browser → your /api/… only |
| Env name | VITE_OPENROUTER_API_KEY | OPENROUTER_API_KEY (server) |
| OpenRouter dashboard | Key unlimited / never rotated | New key + credit limit |
| Vibe Code Health | F on OpenRouter finding | Finding gone after redeploy |
Keep going
- Broader secret rules: API keys in frontend code
- Pre-launch walkthrough: Check if your vibe-coded app is safe before launch
- Glossary and how grades work: /learn
- Free rescan: Vibe Code Health grader
Delete first, proxy second, set a spend limit third, then re-scan. A multi-model chat that “just works” with OpenRouter in the browser is one of the fastest ways vibe coders wake up to an empty credit balance—and one of the easiest leaks to close once you treat sk-or-v1- like the password it is.