# How to get a Grok API key

Sign in at console.x.ai, open API keys and click Create API key, then add credits. Inside: where to paste the key, what the API costs and how to keep it safe.

Tool: Grok. By Julien Lieben. Updated 2026-11-24. Source: https://coldiq.com/university/grok/grok-api-key

## In short

- A Grok API key is a secret code that lets a program use Grok. You create it on the API keys page of the xAI Console, which now opens inside the Grok dashboard at grok.com/dashboard.
- Your Grok account and your API account are the same login, but billing is separate: API usage is paid with prepaid credits.
- xAI lists Grok API access on its paid plans, from Plus. API usage never draws from your plan’s weekly pool; it is billed at standard model rates.
- Store the key in an environment variable named XAI_API_KEY. The API works with the OpenAI SDKs if you set the base URL to https://api.x.ai/v1.
- xAI scans GitHub for leaked keys. If it finds one, it disables the key and emails you.

## Steps

1. Sign in at console.x.ai, which opens the Grok dashboard.
2. Open API keys and click Create API key.
3. Copy the key to a safe place, then add credits under Billing.

## What is a Grok API key?

The API (application programming interface) is how software talks to Grok without the chat window. The API key is the password that proves the request comes from your team.

You need one when a tool asks for “your xAI API key”, when you write a small script, or when you run Grok Build (xAI’s coding agent) in automated jobs.

You do not need one to chat on grok.com or in the Grok app. You also do not need one for Grok Build on your own computer, where you sign in with your account in the browser.


## How do you create a Grok API key?

Keys live in the xAI Console. The old address, console.x.ai, now opens the Grok dashboard, where the API section sits next to your subscription and usage.

1. Go to console.x.ai and sign in with your Grok account, or create one.
2. Open API, then API keys. The page says you can create, rotate and revoke your keys there.
3. Click Create API key and give it a name you will recognize, such as “lead-research-script”.
4. Copy the key right away and store it in a password manager.
5. Open Billing and buy prepaid credits, so your first request does not fail.

Tip: Keys belong to a team. If you are in several teams, check which one is selected before you create the key, or the usage will bill the wrong team.


## Do you have to pay to use the Grok API?

Yes. API usage is billed by the token (a piece of a word) at standard model rates. Most teams use prepaid credits: you buy credits and each request takes its cost from the balance. When the credits run out, requests are rejected.

Your Grok subscription and the API are billed separately, even though you sign in with the same account. As of November 2026, xAI lists Grok API access on the paid plans from Plus ($8 a month), and says API usage does not draw from the plan’s weekly usage pool.

You can turn on auto top-up to buy more credits when the balance drops below a level you choose. The minimum top-up is $5, and you can set a monthly maximum. xAI says prepaid API credits are non-refundable.


## Where do you paste your Grok API key?

Most tools have a settings field named “xAI API key” or “Grok API key”. Paste it there and save.

For your own scripts, the standard is an environment variable (a setting your computer passes to programs) named XAI_API_KEY. On Mac and Linux, run the command at the top of this page in your terminal. On Windows, use the PowerShell version. You can also put it in a .env file in your project, which you never share.

The API follows the same shape as OpenAI’s. A tool built for OpenAI often works with Grok if you set its base URL to https://api.x.ai/v1, its key to your xAI key, and its model to grok-4.7.


## How can you limit what a Grok API key can do?

A key can open every model and endpoint your team has, or only some of them. Through the Management API, an admin can limit a key to certain models, such as grok-4.7, or to certain endpoints, such as chat or image generation.

You can also cap how many requests per second or per minute a key can make. That stops a buggy script from spending your credits in a loop.

Your team’s overall limits depend on its tier. Tiers rise with your total API spend since January 1, 2026: Tier 1 at $50, Tier 2 at $250, Tier 3 at $1,000 and Tier 4 at $5,000. A tier never goes down.


## How do you keep your Grok API key safe?

Anyone with your key can spend your credits. Treat it like a bank card number.

- Never paste it in a chat, a shared doc, a screenshot or a public GitHub repository.
- Do not share one key between teammates. Create one key per person or per tool.
- Keep it in an environment variable or a secrets manager, not in your code.
- Rotate keys from time to time: create a new one, update your tools, then delete the old one.
- If a key may have leaked, open API keys, use the three dots menu to disable or delete it, and create a new one.

Tip: xAI is part of GitHub’s Secret Scanning program. If your key lands in a public repository, xAI disables it and emails you, so expect that tool to stop working until you replace the key.


## Command

```
export XAI_API_KEY="xai-..."
```

## Sources

- [Quickstart](https://docs.x.ai/developers/quickstart)
- [Manage billing](https://docs.x.ai/console/billing)
- [API FAQ: accounts](https://docs.x.ai/console/faq/accounts)
- [API FAQ: security](https://docs.x.ai/console/faq/security)
- [Rate limits](https://docs.x.ai/developers/rate-limits)
- [SpaceXSI pricing](https://x.ai/pricing)

## Questions

**Is the Grok API free?** No. Creating a key costs nothing, but every request is billed per token from prepaid credits or a monthly invoice.

**Is my Grok account the same as my API account?** Yes, the login is shared. Billing is separate: the API uses its own credits, not your Grok plan.

**Where is the xAI Console now?** console.x.ai still works and opens the Grok dashboard, where the API keys, usage and billing pages live.

**Can I use the OpenAI SDK with a Grok API key?** Yes. Set the base URL to https://api.x.ai/v1 and the model to a Grok model such as grok-4.7.


## Related

- [Grok models explained: Grok 3, Grok 4, 4.5, 4.6 and 4.7](https://coldiq.com/university/grok/grok-models)

## Try ColdIQ free

ColdIQ gives new accounts up to 1,450 free credits as they get started, no credit card required.
One subscription covers 40+ B2B data providers for finding, enriching and verifying
contacts and companies, through the web app, the API or the MCP server for AI agents.

1. Create an account: https://coldiq.com/marketplace/sign-up?utm_source=ai-assistant&utm_medium=markdown&utm_content=university
2. Run a first search on your own market with the free credits.
3. Connect the MCP server to Claude, ChatGPT or Cursor: https://coldiq.com/mcp
