Start now

How to create a Grok API key, plus an alternative key

People who search "grok create api key" want a working key and a first successful call. The vendor route is a short trip through the xAI developer console; the route on this site is one click after sign-up and gives you an OpenAI-compatible key for a different, uncensored model.

Last updated

A glowing key hovering above a glass terminal slot connected to a server cube, showing API key setup

Creating a key with the vendor

We are an independent service and not the official xAI API, so for xAI's own key you need xAI's own pages. The flow is common to most providers, and the names of the menus may differ from what follows.

  1. Sign in to the provider's developer console with your account.
  2. Check the billing section. Some providers require a payment method or a deposit before a key works; read what yours asks for.
  3. Open the API keys section and choose to create a new key.
  4. Give it a name that says where it will be used, such as the project or the environment.
  5. Copy the key straight away. Many consoles show the full secret only once.
  6. Store it in a secret manager or an environment variable, never in source code.

If the page layout does not match, the provider's documentation is the authority. Any guide written months ago, including this one, may describe an older interface.

Getting a key here in under a minute

Our key is for an OpenAI-compatible endpoint serving one hosted open-weight model, tuned to answer without content refusals for lawful adult use. Getting one takes five steps.

  1. Open the API key page.
  2. Sign up with Google, or with an email and password.
  3. Click once to claim your $0.50 of trial credit. It is one per person, valid for 7 days, and needs no card.
  4. Copy the key shown on the page.
  5. Run the test call below.

The base URL is https://api.grokaiapikey.com/v1, the model ID is uncensored, and the key goes in an Authorization: Bearer header.

Test the key

Start with curl. If this returns a JSON answer, your key, base URL and model are all correct.

export API_KEY="paste-your-key-here"

curl https://api.grokaiapikey.com/v1/chat/completions   -H "Authorization: Bearer $API_KEY"   -H "Content-Type: application/json"   -d '{"model": "uncensored",
       "messages": [{"role": "user", "content": "Reply with the word ready."}]}'

In Node, the official OpenAI package works after you change two settings.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.grokaiapikey.com/v1",
  apiKey: process.env.API_KEY,
});

const r = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Reply with the word ready." }],
});
console.log(r.choices[0].message.content);

Python users can do the same with OpenAI(base_url=..., api_key=...). The methods available are POST /v1/chat/completions, POST /v1/responses and GET /v1/models.

Setting the key as an environment variable

Never paste a key into source code. Put it in an environment variable, and read it at runtime. The commands differ by system.

# macOS or Linux, current shell session
export API_KEY="paste-your-key-here"

# Windows PowerShell, current session
$env:API_KEY = "paste-your-key-here"

# Check that the variable is set (macOS or Linux)
test -n "$API_KEY" && echo "key is set"

For a project, store the value in a .env file that is listed in .gitignore, and load it with your framework's loader. On a server, use the host's secret store or the deployment platform's environment settings. The base URL for this site is https://api.grokaiapikey.com/v1, and it is safe to keep in code because it is not a secret.

If you run several services, give each its own key. Accounts that have topped up can hold up to 5 keys, so a staging copy, a production copy and a personal test key can all coexist, each with its own label.

If the call fails

SymptomLikely causeFix
401 UnauthorizedMissing or mistyped keyCheck the Bearer header and look for a trailing space or quote
404 Not FoundWrong base URLThe path must be /v1/chat/completions on the api. subdomain
Model errorWrong model nameUse the model ID uncensored
429 rate_limitedToo many requests per minuteTrial keys allow 60 a minute; slow down
429 concurrencyToo many at onceTrial keys allow 2 in flight; a stream holds its slot until it ends

A 429 with a Retry-After: 5 header means temporary overload. Wait the five seconds and retry.

Use the request ID

Every response includes an X-Request-Id header. Log it next to your own error message. If you ask the support team about a failed call, the request ID lets them find that exact call instead of guessing. In curl, add -i to print the response headers, and in the Python SDK you can read them with the raw-response helper.

When a problem is intermittent, the headers also help: X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency show the limits that apply to your key, which tells you at a glance if you are on a trial key or a full one.

Replacing or adding keys

You never need to ask anyone to rotate a key. On the API key page you can regenerate (reissue) the key whenever you want, and the old key stops working at once. Do this the moment a key lands in a public repository, a screenshot or a shared chat.

Accounts that have topped up can hold up to 5 keys. Give each one a label, such as staging or mobile app, and revoke any single key without touching the others. One key per environment is a good habit, because revoking a leaked staging key then costs your production traffic nothing.

Using the key in existing tools

You do not have to write code to use the key. Many chat front ends and developer tools accept a custom OpenAI-compatible endpoint, and SillyTavern is one public example. The setup always asks for the same three values.

  • Base URL or API URL: https://api.grokaiapikey.com/v1
  • API key: the key you copied
  • Model name: uncensored

Some tools want the full path ending in /chat/completions; others add it themselves. If you get a 404, try the other form. If the tool has a model dropdown that stays empty, type the model name by hand, or let it fetch the list from GET /v1/models, which returns the single model ID.

Streaming works through the same settings. If replies appear all at once instead of word by word, look for a streaming toggle in the tool.

Keeping a key safe

  • Keep it server-side. A key placed in browser JavaScript or a mobile app bundle can be read by anyone.
  • Load it from an environment variable and add your env file to .gitignore before the first commit.
  • Set a spending habit: watch the X-Balance-USD response header so an unexpected drop stands out.
  • Use separate keys for separate services so you can revoke one without an outage elsewhere.

Once the test call works, read the docs for streaming, tool calling and JSON mode, and see the pricing page for rates: $0.15 per 1M input tokens and $0.50 per 1M output tokens. If you are weighing this against a closed vendor, our article on why developers switch to uncensored models covers the trade-offs.

A simple rotation routine

  1. On the API key page, create or regenerate the key you want to replace. Regenerating makes the old key stop working at once, so do it when your code is ready to take the new value.
  2. Update the environment variable or secret in every place the key is used.
  3. Restart the service and run the curl test from this article.
  4. Write the date in your notes. A calendar reminder every few months is enough for most projects.

If you hold several labeled keys after a top-up, rotate them one at a time. Revoke the key tied to a laptop or a former teammate first, since those are the likeliest to leak.

Common inquiries

Where do I create an xAI key?

In xAI's developer console, under its API keys section. Menu names change, so follow xAI's current documentation.

Does the key here cost anything to get?

No. After sign-up you can claim $0.50 of trial credit with one click, one per person, valid for 7 days, with no card.

What if my key leaks?

Regenerate it on the API key page. The old key stops working immediately, and you do not need to contact support.

Can I have more than one key?

Yes, once you have topped up. You can hold up to 5 keys, label them and revoke any of them.

Key generation in seconds

Register, copy your token, update the endpoint. That is all configuration required.

Start now