xAI Grok API Guide

SkillSearch

Guide to the xAI Grok API — Elon Musk's AI model with real-time X/Twitter data access. Covers Grok-2 and Grok-3 models, function calling, vision, long context, and unique features like X search integration and real-time knowledge cutoff.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the xAI Grok API Guide skill

What this skill tells your AI

The instructions your AI receives, as published by nirholas/three.ws in data/skills/general/xai-grok-api-guide/SKILL.md and read by ahel’s review.

Grok is xAI's frontier AI model with native X (Twitter) data access. This guide covers API usage, models, and integration patterns.

Why Grok?

FeatureGrok Advantage
Real-time X dataAccess to live tweets, trending topics
No knowledge cutoffTrained on latest data continuously
Humor/personalityMore engaging conversational style
Function callingFull tool support
VisionImage understanding
Long context128K+ context window

Models

ModelContextBest ForPrice (1M tokens)
Grok-3128KComplex reasoning, analysis$5 / $15
Grok-2128KGeneral tasks, faster$2 / $10
Grok-2-mini128KQuick responses, budget$0.50 / $2

Quick Start

curl https://api.x.ai/v1/chat/completions \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-3",
    "messages": [
      {"role": "user", "content": "What is trending in crypto on X right now?"}
    ]
  }'

OpenAI-Compatible API

import OpenAI from 'openai';

const xai = new OpenAI({
  baseURL: 'https://api.x.ai/v1',
  apiKey: process.env.XAI_API_KEY,
});

const response = await xai.chat.completions.create({
  model: 'grok-3',
  messages: [
    { role: 'system', content: 'You are a crypto market analyst.' },
    { role: 'user', content: 'Analyze $SPA on X/Twitter.' }
  ]
});

Function Calling

const response = await xai.chat.completions.create({
  model: 'grok-3',
  messages: [{ role: 'user', content: 'What is the price of SPA?' }],
  tools: [
    {
      type: 'function',
      function: {
        name: 'getTokenPrice',
        description: 'Get the current price of a cryptocurrency token',
        parameters: {
          type: 'object',
          properties: {
            symbol: { type: 'string', description: 'Token symbol (e.g., SPA, ETH)' },
            chain: { type: 'string', description: 'Blockchain (e.g., arbitrum)' }
          },
          required: ['symbol']
        }
      }
    }
  ]
});

X/Twitter Integration

Grok has unique access to X data:

Searching X

const response = await xai.chat.completions.create({
  model: 'grok-3',
  messages: [
    {
      role: 'user',
      content: 'Search X for posts about Sperax USDs and summarize the sentiment'
    }
  ]
});
// Grok natively searches X and returns real-time results

Trending Analysis

const response = await xai.chat.completions.create({
  model: 'grok-3',
  messages: [
    { role: 'user', content: 'What crypto topics are trending on X in the last 24 hours?' }
  ]
});

Use Cases for Crypto

Use CaseModelAdvantage
Sentiment analysisGrok-3Native X data access
Trending tokensGrok-3Real-time social data
News monitoringGrok-2Fast, always current
Community pulseGrok-3X conversation analysis
Influencer trackingGrok-2Track crypto influencers on X

SperaxOS Integration

Grok is available as a model provider in SperaxOS:

XAI_API_KEY=xai-...

Best used for:

  • X/Twitter social intelligence tools
  • Real-time crypto news analysis
  • Community sentiment monitoring
  • Social-first agent personalities

Links

Signals

GitHub stars
114
Forks
29
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
xai-grok-api-guide
Source
github.com/nirholas/three.ws