AI · Secret guide

Leaked xAI API Key: what to do in the first hour

High severityDetected onlyLast verified · 5 min read

An xAI API key lets whoever holds it call the Grok models through the xAI API, with the usage billed to the team that owns the key. It does not give access to anyone’s X account and it does not reach your servers: the damage is the spend, the rate limit you share with your own application, and whatever data your prompts and logs contain. Replace the key first, then look at how it was used.

Check your GitHub account for leaked secrets — free

Provider
xAI
Severity
High
Impact
SaaS account access and billing
Checked live by LeakWatch
No

What an xAI API key looks like

xAI keys start with the literal prefix xai-, followed by a long run of letters and digits, between 60 and 120 characters after the prefix:

xai-…XXXX   xAI API key (masked, long alphanumeric body)

The prefix is lowercase and case-sensitive. A string written XAI- is not a key, and the variable that usually holds one is XAI_API_KEY. The xai- prefix is easy to tell apart from sk- (OpenAI, Anthropic), gsk_ (Groq) or sk-or- (OpenRouter) keys, so a match is rarely ambiguous. Because xAI exposes an API that follows the same request shape as other providers, the key is often pasted into tools that were written for another vendor, which is one way it ends up in unexpected places.

How xAI API keys get leaked

  • A .env file committed by accident, or an example file filled with the real value to make a demo run.
  • OpenAI-compatible clients. The same code is pointed at a different base URL and a different key, and the key is hardcoded in the client constructor.
  • Agent and editor configuration. Coding agents, MCP configuration files and IDE plugins that store the key in plain text, then end up in a public dotfiles repository.
  • Front-end code. A key placed in JavaScript so a page can talk to the API directly, where every visitor can read it.
  • Notebooks, gists and bug reports. A key pasted in a cell, a gist or a screenshot while asking for help.

What to do in the first hour

  1. Find the key in the xAI console. Open the API Keys section of the xAI console. The list shows each key’s name and its last characters, which you can match against the leaked value.
  2. Create a replacement key and note what it is allowed to do. If the console lets you limit a key to specific endpoints or models, restrict it to what the service really calls.
  3. Deploy the new key to the application or secret store that used the old one, and confirm that a request still succeeds.
  4. Delete the exposed key from the same list. A deleted key should be rejected by the API; confirm this with a test request if you want to be sure.
  5. Check usage and billing. Look at the usage and spend figures for the team since the exposure: request volume you cannot explain, models you never use, activity at hours when nobody works. Figures can lag, so check again a few hours later.
  6. Review team access. If the key belonged to a shared team, check the member list and any other keys created recently.
  7. Look for neighbours. A repository that held an xAI key often holds other providers’ keys in the same file. Rotate each at its own provider, then remove the values from the code. See I accidentally pushed an API key to GitHub.

Not sure what else leaked from the same repository? Run a free scan.

Not sure what else leaked? Run a free scan.

Revoke it at xAI

xAI keys are managed from the API keys page of the xAI console, after you sign in with an account that belongs to the team owning the key. Find the exposed key and delete it. If you cannot find it, check whether you are looking at the right team: keys belong to the team in which they were created. We have not had this procedure confirmed by a person, and the console can change, so if the wording differs from this guide, look for the section where API keys are created and listed, and see xAI’s own documentation.

How LeakWatch detects it

The rule is called xAI API Key. It recognizes the lowercase xai- prefix followed by 60 to 120 letters and digits, with word boundaries on both sides, so it does not need a variable name next to the value. A shorter string, or one written in capitals, is not reported. The severity is high: the key opens a paid third-party service rather than your own infrastructure. This type is not checked live: LeakWatch does not send any request to xAI with the key it found.

LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.

FAQ

Can someone read my X account or my Grok chats with this key?

No. The API key authorizes requests to the models under your team. It does not open an X account or the chat history of the consumer apps. What it exposes is your quota, your bill and the ability to run requests as you.

Does deleting the commit make the key safe again?

No. Public commits are copied by scanners within minutes, so the key must be treated as known. Delete the key in the console first, and clean the history afterwards.

The key was only in a private repository. Should I still replace it?

Yes if the repository has collaborators, forks or CI logs, or if you are unsure who can read it. Creating a new key costs a minute, and a key you doubt is worth less than a fresh one.

Get alerted next time a secret leaks — create a free account

LeakWatch is not affiliated with xAI.