Overview

xAI's Grok models offer unique capabilities for code assistance. When integrated with Autohand, you get:

  • Access to Grok-2 and Grok-2 mini models
  • Real-time knowledge from X (Twitter) data
  • Large 128K context window
  • Vision capabilities for image understanding
  • Function calling support

API access: xAI API is available through console.x.ai. You'll need an xAI account with API access enabled.

Setup

Get started with xAI Grok.

Get your API key

  1. Go to console.x.ai and sign in
  2. Navigate to API Keys
  3. Create a new API key and copy it

Configure Autohand

# Set environment variable
export XAI_API_KEY="xai-xxxxxxxxxxxxxxxxxxxx"

# Or configure via CLI
autohand config set xai.apiKey "xai-xxxxxxxxxxxxxxxxxxxx"

Verify your configuration:

# Start with xAI provider
autohand --provider xai --model grok-2

# Test with a prompt
autohand --prompt "Hello, which model are you?"

CLI configuration

Configure xAI in your ~/.autohand/config.json:

{
  "provider": "xai",
  "xai": {
    "apiKey": "${XAI_API_KEY}",
    "model": "grok-2",
    "maxTokens": 4096,
    "temperature": 0.7
  }
}

Configuration options

OptionDescriptionDefault
apiKeyYour xAI API key-
modelModel to usegrok-2
maxTokensMaximum tokens in response4096
temperatureResponse randomness (0-2)0.7
baseUrlAPI endpointhttps://api.x.ai/v1

Available models

xAI offers Grok models optimized for different use cases.

ModelContextBest for
grok-2128KMost capable, complex tasks
grok-2-mini128KFast and cost-effective
grok-2-vision128KImage understanding

Switch models

# Set default model
autohand config set model "grok-2"

# Use during a session
/model xai/grok-2-mini

Best practices

  • Use environment variables: Keep API keys out of version control.
  • Choose the right model: Use grok-2 for complex tasks, grok-2-mini for quick responses.
  • Monitor usage: Check your xAI console for usage metrics.

Resources

Troubleshooting

Common issues

IssueSolution
Invalid API keyVerify key at console.x.ai
Rate limitedWait or check your rate limits
Model not availableCheck model access in your account

Debug mode

# Enable verbose logging
AUTOHAND_DEBUG=true autohand --provider xai