home / skills / openclaw / skills / xai

xai skill

This skill chat with Grok models via xAI API, enabling text and vision analysis with quick model selection and results.

npx playbooks add skill openclaw/skills --skill xai

Review the files below or copy the command above to add this skill to your agents.

Files (7)
SKILL.md
1.9 KB
---
name: xai
description: Chat with Grok models via xAI API. Supports Grok-3, Grok-3-mini, vision, and more.
homepage: https://docs.x.ai
triggers:
  - grok
  - xai
  - ask grok
metadata:
  clawdbot:
    emoji: "🤖"
---

# xAI / Grok

Chat with xAI's Grok models. Supports text and vision.

## Setup

Set your API key in the skill config:

```bash
# Via clawdbot config
clawdbot config set skills.entries.xai.apiKey "xai-YOUR-KEY"

# Or environment variable
export XAI_API_KEY="xai-YOUR-KEY"
```

Get your API key at: https://console.x.ai

## Commands

### Chat with Grok
```bash
node {baseDir}/scripts/chat.js "What is the meaning of life?"
```

### Use a specific model
```bash
node {baseDir}/scripts/chat.js --model grok-3-mini "Quick question: 2+2?"
```

### Vision (analyze images)
```bash
node {baseDir}/scripts/chat.js --image /path/to/image.jpg "What's in this image?"
```

### 🔍 Search X/Twitter (Real-time!)
```bash
node {baseDir}/scripts/search-x.js "Remotion video framework"
node {baseDir}/scripts/search-x.js --days 7 "Claude AI tips"
node {baseDir}/scripts/search-x.js --handles @remotion_dev "updates"
```

Uses xAI Responses API with x_search tool for real X posts with citations.

### List available models
```bash
node {baseDir}/scripts/models.js
```

## Available Models

- `grok-3` - Most capable, best for complex tasks
- `grok-3-mini` - Fast and efficient
- `grok-3-fast` - Optimized for speed
- `grok-2-vision-1212` - Vision model for image understanding

## Example Usage

**User:** "Ask Grok what it thinks about AI safety"
**Action:** Run chat.js with the prompt

**User:** "Use Grok to analyze this image" (with attached image)
**Action:** Run chat.js with --image flag

**User:** "What Grok models are available?"
**Action:** Run models.js

## API Reference

xAI API Docs: https://docs.x.ai/api

## Environment Variables

- `XAI_API_KEY` - Your xAI API key (required)
- `XAI_MODEL` - Default model (optional, defaults to grok-3)

Overview

This skill lets you chat with xAI's Grok models from a command-line environment and scripts. It supports multiple Grok variants including text and vision-capable models, enabling conversational prompts, image analysis, and real-time X/Twitter search. Configuration is quick via an API key and optional default model setting.

How this skill works

The skill calls the xAI Responses API to send prompts and receive model outputs. You set your XAI_API_KEY in config or environment variables, choose a model (or use the default), and run provided scripts to chat, analyze images, list available models, or search real-time X posts. Image inputs are uploaded and processed by the vision models when using the --image flag.

When to use it

  • When you need conversational AI responses from Grok for brainstorming or coding help.
  • When you want to analyze or describe images using Grok vision models.
  • When you require fast, efficient responses and can choose a smaller Grok variant.
  • When you need real-time X/Twitter search results with model commentary and citations.
  • When you want a simple CLI integration to experiment with xAI models.

Best practices

  • Store your XAI_API_KEY securely in environment variables or the bot config, not in source code.
  • Specify a model for task-sensitive work (grok-3 for complex tasks, grok-3-mini for speed).
  • Include concise prompts and system context for more predictable outputs.
  • Use the --image flag only with supported vision models and provide clear image paths.
  • Rate-limit requests and handle API errors gracefully in automation scripts.

Example use cases

  • Run a quick conversation: node scripts/chat.js "What is the meaning of life?"
  • Ask a vision model to describe a photo: node scripts/chat.js --image /path/photo.jpg "What's in this image?"
  • Fetch recent X posts about a topic and get model analysis: node scripts/search-x.js "Remotion video framework"
  • Switch to a lightweight model for speed: node scripts/chat.js --model grok-3-mini "Quick math"
  • List available models to decide which one to use: node scripts/models.js

FAQ

How do I provide my xAI API key?

Set XAI_API_KEY in your environment or add it to the skill config using the bot config command.

Which model should I pick for image analysis?

Choose a vision-capable variant such as grok-2-vision-1212 for image understanding; use grok-3 for complex multimodal reasoning.