Skip to main content

Adding Your API Key

Grok-X requires an xAI API key to communicate with the Grok Responses API. Add your key to Claude Code’s settings file:
1

Open settings.json

Edit ~/.claude/settings.json (create it if it doesn’t exist).
2

Add your API key

Add the following configuration:
{
  "env": {
    "XAI_API_KEY": "xai-your-key-here",
    "GROK_X_DEFAULT_MODEL": "grok-4-1-fast-reasoning"
  }
}
Replace xai-your-key-here with your actual API key.
Keep your API key secure. Never commit settings.json to version control or share it publicly.

Configuration Options

XAI_API_KEY (Required)

Your xAI API key for authenticating requests to the Grok API.
{
  "env": {
    "XAI_API_KEY": "xai-your-key-here"
  }
}

GROK_X_DEFAULT_MODEL (Optional)

The default Grok model to use for queries. If omitted, the skill defaults to grok-4-1-fast-reasoning.
{
  "env": {
    "XAI_API_KEY": "xai-your-key-here",
    "GROK_X_DEFAULT_MODEL": "grok-4-1-fast-reasoning"
  }
}
You can override the model per-query using the --fast or --deep flags, regardless of this setting.

Getting an xAI API Key

To obtain an API key from xAI:
1

Visit the xAI console

2

Sign in

Sign in with your X (Twitter) account.
3

Navigate to API Keys

Click API Keys in the left sidebar.
4

Create a new key

Click Create key to generate a new API key.
5

Copy and save

Copy the key (it begins with xai-) and add it to ~/.claude/settings.json as shown above.
xAI API keys always begin with the prefix xai-.

Verifying Configuration

To verify your configuration is working correctly, try running a simple query from within Claude Code:
/grok-x "What is trending on X today?"
If configured correctly, Grok-X will execute the query and return results from the live X platform.
If you see an error about XAI_API_KEY environment variable not set, double-check that your settings.json file is properly formatted and located at ~/.claude/settings.json.

Next Steps

With Grok-X configured, you’re ready to start using it! Check the Usage guide to learn about all available commands and features.

Build docs developers (and LLMs) love