Quick answer
Go to console.x.ai and sign in or create an xAI account. The xAI account FAQ says an account already used for Grok can also be used for the xAI API, though billing is separate. To call the API, create an API key from the console’s API Keys page and send it with your requests as a Bearer token. Signing into Grok or the console does not, by itself, authenticate API calls. (xAI account FAQ)
Sign in or create an xAI API account
- Open
console.x.aiand sign in, or create an account. The API quickstart says to add credits to the account to start using the API. (xAI API quickstart) - If you already use Grok, you can use that shared xAI account for API access. Manage sign-in details at
accounts.x.ai. An xAI account is distinct from an X account, although the FAQ says you can choose X sign-up to link an X account to your xAI account. (xAI account FAQ) - In the console, open API Keys and create an API key. The quickstart says to export it or store it as an environment variable such as
XAI_API_KEY. (xAI API quickstart)
Grok and xAI API billing are separate. The account FAQ does not say that a Grok subscription is required for API access. (xAI account FAQ)
Make a first API request
An API key—not your website login session—is the credential sent with an inference request. The official xAI example uses the Responses endpoint, the grok-4.7 model, and a string for input. The request below follows that documented example:
export XAI_API_KEY="your_api_key"
curl https://api.x.ai/v1/responses \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.7",
"input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"
}'
The Responses reference describes the raw response as an object with an output array. In SDK examples, generated text is available as response.output_text. (Responses API reference; xAI API overview)
Keep the key private: do not put it in browser-side code or public repositories. If it is exposed, rotate or replace it in the console. (xAI API Security FAQ)
Don’t confuse an API key with a Management API key
A regular API key authenticates inference requests to https://api.x.ai. A Management API key is a separate credential for administrative operations such as managing team API keys; xAI documents it under Console → Settings → Management Keys and uses it with https://management-api.x.ai. Do not use the Management API credential or host for an ordinary Grok model request. (xAI Management API guide)
If sign-in or a request fails
- Can’t sign in? Manage xAI sign-in details at
accounts.x.ai. If you use MFA, the account FAQ says recovery codes are available through the xAI Accounts Security page. (xAI account FAQ) - API request is unauthorized? Check that you copied the inference API key, that it is active, and that the request includes
Authorization: Bearer .... Confirm you are calling the inference host,api.x.ai, not the Management API host. (xAI Inference API reference) - Need to manage team keys programmatically? Use the Management API and its separate management key; its key-creation examples are administrative operations, not inference requests. (xAI Management API guide)
