VibeCodeHealth

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:

  1. You create a key on OpenRouter’s API keys page.
  2. The model writes fetch("https://openrouter.ai/api/v1/chat/completions", { headers: { Authorization: \Bearer ${key}` } })` in a client component.
  3. Vite or Next inlines it via import.meta.env.VITE_OPENROUTER_API_KEY or NEXT_PUBLIC_OPENROUTER_API_KEY.
  4. 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

  1. Open your production site → DevTools → Network → send a chat message.
  2. If the browser talks to openrouter.ai with an Authorization: Bearer sk-or-v1-… header, the key is public.
  3. Or search Sources / “Search in all files” for sk-or-v1- or openrouter.ai.
  4. 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:

  1. Delete the leaked key; create a new one with a spend limit.
  2. Store it as server-only OPENROUTER_API_KEY (no public prefix).
  3. Expose a small API route or edge function your UI calls.
  4. 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

  1. Delete sk-or-v1- from chat-generated files and any “public” env toggle.
  2. Add a backend/cloud function the builder supports (or export to GitHub and add a Vercel/Netlify/Supabase function).
  3. Put the new key only in private secrets; set a credit limit in OpenRouter.
  4. Redeploy; confirm Network no longer shows openrouter.ai Bearer tokens from the client.
  5. Re-scan on Vibe Code Health and skim related notes on /learn.

OpenRouter vs OpenAI vs Groq (same rule, different prefix)

VendorTypical secret prefixBrowser OK?
OpenRoutersk-or-v1- + 64 hexNever
OpenAIsk-proj-, sk-svcacct-, legacy sk-Never
Anthropicsk-ant-Never
Groqgsk_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

SignalStill brokenFixed
Bundle search for sk-or-v1-HitNo hit
Network on chat sendBrowser → openrouter.ai with BearerBrowser → your /api/… only
Env nameVITE_OPENROUTER_API_KEYOPENROUTER_API_KEY (server)
OpenRouter dashboardKey unlimited / never rotatedNew key + credit limit
Vibe Code HealthF on OpenRouter findingFinding gone after redeploy

Keep going

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.

Grade your app next

Passive scan only—no login, no crawl of your whole site.

Open the scanner

Platform checkers

Free A–F grades written for the host you ship on.