BuildBotsBetter
xAI

Set Up Grok Build (xAI)

CLI Setup, xAI Authentication & Frontier Reasoning Automation

Progress
0%

Select Your Operating System

Commands and environment variables update instantly to match your target shell.

Step 1 of 6 Est: 2 minutes

Verify Python Runtime & Package Installer

Grok Build CLI requires Python 3.10 or higher with pip package management.

Check Installed Python Version

Open your terminal and confirm your Python version and pip availability:

PowerShell
PS > python --version; pip --version
zsh
$ python3 --version && pip3 --version
bash
$ python3 --version && pip3 --version
💡
Need a newer Python? If your system version is below 3.10, install Python 3.11 or 3.12 from python.org or via your system package manager (e.g., brew install python@3.11 on macOS).
Checkpoint 1
Required

Paste the exact output of your Python version command below (e.g. Python 3.11.4):

Step 2 of 6 Est: 3 minutes

Install Grok Build CLI Package

Install the xAI Grok CLI package and verify that the executable is located in your system PATH.

Install via Package Manager

Install the official Grok CLI package and inspect its version:

PowerShell
PS > pip install xai-cli PS > grok --version
zsh
$ pip3 install --user xai-cli $ grok --version
bash
$ pip3 install --user xai-cli $ grok --version
⚠️
Executable PATH Warning: If the shell cannot find grok, ensure your Python Scripts or ~/.local/bin directory is included in your system PATH variable.
Checkpoint 2
Required

Paste the output of grok --version to verify binary installation:

Step 3 of 6 Est: 3 minutes

Configure xAI API Authentication

Generate an API key in the xAI Console and store it in your environment variables.

Set Persistent XAI_API_KEY

Generate a key starting with xai- at console.x.ai and save it in your shell environment:

PowerShell
# Set persistent user variable and current session variable PS > [System.Environment]::SetEnvironmentVariable('XAI_API_KEY', 'xai-your-key-here', 'User') PS > $env:XAI_API_KEY = 'xai-your-key-here' PS > python -c "import os; print('Key set:', bool(os.environ.get('XAI_API_KEY')))"
zsh
# Append to ~/.zshrc and export for current session $ echo 'export XAI_API_KEY="xai-your-key-here"' >> ~/.zshrc $ export XAI_API_KEY="xai-your-key-here" $ test -n "$XAI_API_KEY" && echo "Key configured successfully"
bash
# Append to ~/.bashrc and export for current session $ echo 'export XAI_API_KEY="xai-your-key-here"' >> ~/.bashrc $ export XAI_API_KEY="xai-your-key-here" $ test -n "$XAI_API_KEY" && echo "Key configured successfully"
💡
Billing Note: xAI API tokens are billed through console.x.ai and require prepaid credits separate from X social media subscriptions.
Checkpoint 3
Required

Paste your API key prefix (e.g. xai-...) or the confirmation text showing key is active:

Step 4 of 6 Est: 3 minutes

Interactive Terminal Session & Repo Context

Launch an interactive Grok session inside your repository and explore codebase context indexing.

Start Interactive Grok Session

Launch Grok interactive mode inside your project workspace:

PowerShell
# Start interactive Grok session with grok-2 model PS > grok chat --model grok-2
zsh
# Start interactive Grok session with grok-2 model $ grok chat --model grok-2
bash
# Start interactive Grok session with grok-2 model $ grok chat --model grok-2
💡
In-Session Commands: Type /help inside the session to view commands, /model grok-2-mini to switch to low-latency mode, and /exit to quit.
Checkpoint 4
Required

Paste the interactive session banner or prompt confirming active connection:

Step 5 of 6 Est: 3 minutes

Non-Interactive Execution & STDIN Piping

Execute single-shot prompt queries and pipe repository files directly into Grok for automated code quality reviews.

Run Single Query & Pipe File Content

Pass queries directly or stream file contents through standard input:

PowerShell
# Single-shot command execution PS > grok prompt "Explain what makes xAI Grok-2 reasoning unique in 2 sentences" # STDIN piping in PowerShell PS > Get-Content package.json | grok prompt "Identify any outdated dependency specifications"
zsh
# Single-shot command execution $ grok prompt "Explain what makes xAI Grok-2 reasoning unique in 2 sentences" # STDIN piping in zsh $ cat package.json | grok prompt "Identify any outdated dependency specifications"
bash
# Single-shot command execution $ grok prompt "Explain what makes xAI Grok-2 reasoning unique in 2 sentences" # STDIN piping in bash $ cat package.json | grok prompt "Identify any outdated dependency specifications"
Checkpoint 5
Required

Paste the response generated by your grok prompt command:

Step 6 of 6 Est: 2 minutes

Default Configuration & Run It Later Card

Lock in persistent model defaults and save the quick reference card for daily terminal development.

Set Default Model Preferences

Configure your preferred default model and inspect configuration settings:

PowerShell
PS > grok config set model grok-2 PS > grok config list
zsh
$ grok config set model grok-2 $ grok config list
bash
$ grok config set model grok-2 $ grok config list
Checkpoint 6
Required

Paste the output of grok config list showing your saved preferences:

⚡ Run It Later — Quick Reference

Interactive Chat grok chat --model grok-2 Starts interactive conversation with deep codebase reasoning
Fast Mini Mode grok prompt --model grok-2-mini "lint" Low-latency model for rapid audits and cost savings
Pipe File Analysis cat src/main.py | grok prompt "Refactor" Streams code directly into Grok prompt for terminal reviews
Project Indexing grok --context . "Find memory leaks" Scans entire repository structure respecting .gitignore