EN ▾
Get API key

Uncensored API, transparent billing.

https://api.grokunrestricted.cc/v1

AI API Key Security: Practical Steps for Developers

AI API key security comes down to one idea: the key is a bearer password, so anyone holding the string can spend your balance. Below are the places keys leak, the habits that prevent it, and a recovery routine for the day one does.

Updated

A key inside a glass vault with glowing circuit lines, representing protected API credentials

What an API key is, in plain terms

An API key is a long random string that identifies your account to a service. With an OpenAI-compatible endpoint, you send it in the header Authorization: Bearer <key> on every request. There is no second factor and no check on where the call comes from. The server sees a valid string and does the work.

That makes a key closer to a password than to a username. If a stranger copies it, they can send requests until your balance is empty or you stop them. On a pay-as-you-go service the loss is real money: the person who found your key does not need to break anything, they only need to run a script.

The same logic applies to our hosted text API, which works with any OpenAI SDK once you point it at the right base URL. The key you copy from the API key page is the only credential, so everything below applies to it directly.

Where keys leak most often

Most leaks are not attacks. They are small convenience choices that nobody revisited. These are the usual ones, roughly in order of how often they happen.

  1. Committed to git. A hard-coded string in a script, or a .env file that was never ignored. Deleting it in a later commit does not help, because the history still contains it.
  2. Shipped to the browser. A key placed in front-end JavaScript is visible to every visitor through the network tab.
  3. Bundled in a mobile app. Binaries can be unpacked, and strings extracted in minutes.
  4. Pasted into chats and tickets. Screenshots, issue trackers and support threads keep copies for years.
  5. Printed to logs. Debug output that dumps request headers writes the key to disk, then to a log aggregator.
  6. Shared notebooks and gists. A notebook with outputs saved can include the key in an error message.

Automated scanners crawl public repositories constantly, so a key pushed even briefly should be treated as exposed.

Store the key where code can read it but people cannot see it

The simplest safe pattern is an environment variable that your process reads at start-up. For local work, keep it in a .env file and add that file to .gitignore before the first commit.

# .gitignore
.env
.env.*

# shell: set for this session only
export UNCENSORED_API_KEY="paste-your-key-here"

Then read it in code and fail loudly if it is missing, rather than falling back to a default string.

import os
from openai import OpenAI

key = os.environ.get("UNCENSORED_API_KEY")
if not key:
    raise SystemExit("UNCENSORED_API_KEY is not set")

client = OpenAI(base_url="https://api.grokunrestricted.cc/v1", api_key=key)
reply = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(reply.choices[0].message.content)

On servers, use whatever secret store your platform offers: the host's secret manager, a CI secret variable, or an encrypted file readable only by the service user. The point is that the key does not live in the repository, in the image layers, or in the build output.

Keep the browser and the app away from the key

If you build a web page or mobile client that needs model output, put a small server between the client and the API. The client calls your server, the server adds the key and forwards the request. Visitors never see the credential.

// server.js (Node 18+, no dependencies)
import http from "node:http";

const KEY = process.env.UNCENSORED_API_KEY;

http.createServer(async (req, res) => {
  if (req.method === "POST" && req.url === "/chat") {
    await handle(req, res);
  } else {
    res.writeHead(404).end();
  }
}).listen(3000);

async function handle(req, res) {
  let body = "";
  for await (const chunk of req) body += chunk;
  const { prompt } = JSON.parse(body);

  const upstream = await fetch("https://api.grokunrestricted.cc/v1/chat/completions", {
    method: "POST",
    headers: {
      "Authorization": "Bearer " + KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "uncensored",
      messages: [{ role: "user", content: String(prompt).slice(0, 4000) }],
      max_tokens: 500,
    }),
  });
  res.writeHead(upstream.status, { "Content-Type": "application/json" });
  res.end(await upstream.text());
}

Notice the two guards: the proxy trims the prompt and sets max_tokens. Without them, anyone who finds your proxy can send an 8 MB body and a huge completion request on your balance. In a real app, also add your own login check and a per-user rate limit in front of this handler.

Limit the damage before something goes wrong

You cannot make a leak impossible, but you can make it cheap. Our service is prepaid, so the worst case is the balance on the account, not a surprise invoice. Keep that balance sized to a few weeks of real use, not a year of it. Top-ups start at $20, so a small balance is easy to maintain.

The platform also limits how fast a thief can spend. A full key allows 8 concurrent requests and 300 requests per minute, and a trial key allows 2 and 60. Those ceilings are shared by everyone using the key, including you, so a flood of unexpected traffic will also push your own app into HTTP 429 responses with the code rate_limited or concurrency. Treat sudden 429s on a quiet day as a signal, not just a nuisance.

Two more habits help. First, log the X-Request-Id response header with each call, so support can find a specific request if you ask. Second, never log the Authorization header itself. Redact it in your HTTP client or logging middleware.

Detect misuse early

Every response includes an X-Balance-USD header. A scheduled job that reads it once an hour and compares it with the previous reading gives you a cheap leak detector.

curl -s -D - -o /dev/null https://api.grokunrestricted.cc/v1/chat/completions   -H "Authorization: Bearer $UNCENSORED_API_KEY"   -H "Content-Type: application/json"   -d '{"model":"uncensored","messages":[{"role":"user","content":"ping"}],"max_tokens":1}'   | grep -i x-balance-usd

The check costs a fraction of a cent. Compare the number with what your own traffic should have used. If the balance falls faster than your logs explain, someone else is using the key. Also watch for requests in your provider-side history that you did not send, if your account page shows any.

If a key leaks: the first hour

Decide the routine now, while nothing is on fire.

  1. Stop the exposure. Remove the key from the public place and take down the page, repo or paste where it appeared.
  2. Get a replacement and cut over. Check the API key page for what your account allows, and write to support if you need the old key disabled. Update the environment variable in every place the app runs, then restart.
  3. Check the balance. Compare the current value with the last known one to see what was spent.
  4. Find the cause. Read the git history, build logs and shared documents, and fix the process, not just the symptom.
  5. Write it down. A three-line note on what happened and what changed prevents a repeat.

On privacy, prompts sent through the service are not used for training, and the privacy page covers the rest. Keep in mind that your key protects access, not content: do not paste secrets or personal data into prompts you would not want stored in a log.

Questions and answers

Is it safe to put an AI API key in front-end JavaScript?

No. Anything shipped to the browser is visible to every visitor. Call the API from a server and keep the key in an environment variable there.

What should I do if I committed my key to GitHub?

Treat it as exposed even if you delete the file, because git history keeps it. Replace the key, update your deployments, and check your balance for unexpected spending.

How does prepaid billing help with key security?

Your loss is limited to the credit on the account, since there is no postpaid invoice. A modest balance and a regular balance check keep the worst case small.

Can I use the same key in several apps?

You can, but they then share one rate limit and one balance, and one leak affects all of them. Keeping apps on separate keys, where your account allows it, makes problems easier to trace.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key