← Blog

Claude API Key Storage in Browser Extensions: Guide

2026-11-21 · 5 min read · SubToAPI Team

If you're building a Chrome or Firefox extension that calls the Claude API, the question isn't "how do I store the key" — it's "why am I storing it in the extension at all." Any value you put in chrome.storage.local, chrome.storage.sync, a content script, or even a background service worker can be extracted by anyone who installs your extension and opens DevTools or unpacks the .crx file. There is no browser storage API that keeps a secret secret once it ships to a user's machine.

That's the direct answer: you should not store a long-lived, full-privilege Anthropic API key inside a browser extension at all. Instead, the extension should talk to a backend (your own server or a proxy service) that holds the real key server-side, and the extension should only ever hold a short-lived or scoped credential — ideally one that's safe to leak. Below is how to actually implement that, and where chrome.storage still has a legitimate role.

Why "just store it securely" doesn't work

Browser extensions run entirely on the client. Even Manifest V3's service workers and isolated contexts don't change the fundamental fact: the code and any data it touches are on the user's disk, inspectable via chrome://extensions → "Inspect views", or extractable by unpacking the extension package. Encrypting the key client-side doesn't help either — if the extension can decrypt it to make a request, so can anyone reading the extension's JavaScript.

This matters more for Claude API keys than for, say, a Google Maps key, because an Anthropic API key is billed per token and has no built-in per-origin restriction. A leaked key can be used by anyone, from anywhere, against your account's quota and bill.

The pattern that actually works: proxy, don't embed

The standard fix is a thin backend between the extension and the model API:

  1. The extension authenticates the user (OAuth, a login flow, or an API key scoped to that user).
  2. Requests go to your server, not directly to api.anthropic.com.
  3. Your server holds the real Claude credentials and forwards the request.
  4. The server enforces per-user rate limits, logs usage, and can revoke access instantly.

This is exactly the gap SubToAPI fills if you don't want to build and run that proxy yourself. You connect your Claude access once, and SubToAPI issues application-scoped keys (sub_live_...) that you can safely distribute to client code — including a browser extension — because each key is independently revocable, rate-limitable, and tracked separately in usage metadata. The real underlying credential never leaves the dashboard.

A minimal extension-side call looks like this:

// background.js (service worker, Manifest V3)
async function askClaude(prompt) {
  const res = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${SUBTOAPI_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "claude-sonnet-4-5",
      max_tokens: 512,
      messages: [{ role: "user", content: prompt }]
    })
  });
  return res.json();
}

Even here, SUBTOAPI_KEY is still client-visible — see below for how to scope the blast radius. Full request/response shape is in the messages docs, and the quickstart covers getting a key in under five minutes.

If you must keep a key in the extension, scope it hard

Sometimes a full server-side proxy is overkill for a side project. If you're going to ship a key with the extension anyway, limit the damage:

SubToAPI's dashboard supports this pattern directly: create a separate key per extension or per team seat under pricing, set limits, and kill a specific key the moment you see abuse — without rotating credentials for every other integration you run.

Where chrome.storage still matters

Once you've removed the "real" secret from the picture, chrome.storage.local is fine for what's left:

// Store a short-lived session token after login
chrome.storage.local.set({ sessionToken: token, expiresAt: Date.now() + 3600_000 });

// Read it back before a request
chrome.storage.local.get(["sessionToken", "expiresAt"], (data) => {
  if (Date.now() > data.expiresAt) {
    // re-authenticate instead of reusing a stale token
  }
});

chrome.storage.sync syncs across a user's devices via their Google account — never put credentials there, since sync storage isn't end-to-end encrypted in a way you control, and it multiplies your exposure across every device the user is logged into.

Streaming and tool calls from an extension

If your extension needs streaming responses (for a live-typing assistant UI) or tool use (for actions inside the page), route those through the same proxy rather than opening a direct connection from the content script. See streaming and tools for the request formats — the extension-side code is identical to a normal web client, it just points at your proxy's URL instead of Anthropic's directly.

questions

Can I store an Anthropic API key in chrome.storage.local and call it secure? No. Anything in chrome.storage is readable by the extension's own code and inspectable by the user via DevTools or by unpacking the extension. It's storage, not a secret manager.

What's the safest architecture for a Claude-powered browser extension? A backend proxy (self-hosted or a service like SubToAPI) holds the real credentials; the extension only holds a scoped, revocable, rate-limited key or session token.

Does Manifest V3 make key storage safer than Manifest V2? Not for secrets. MV3's service workers isolate background logic from content scripts, but any value the extension can use in a request can also be extracted from the extension's packaged files or runtime memory.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →