Skip to content
xai-grok logo

Xai Grok

xai-grok

xAI Grok API: OpenAI-compatible at api.x.ai/v1, grok-3/grok-3-mini for fast AI reasoning

SKILL.md

Full skill instructions

xai-grok

Purpose

This skill enables interaction with the xAI Grok API, an OpenAI-compatible service for fast AI reasoning tasks. It provides access to models like grok-3 and grok-3-mini via api.x.ai/​v1, allowing developers to integrate advanced AI capabilities for text generation, reasoning, and more.

When to Use

Use this skill when you need quick AI inference for applications requiring natural language processing, such as chatbots, code generation, or data analysis. Opt for it over other APIs if you're already using OpenAI-compatible tools and want xAI's specialized models for faster responses, especially in scenarios with real-time constraints like live customer support or dynamic content creation.

Key Capabilities

  • Access endpoints at api.x.ai/​v1 for chat completions, embeddings, and model streaming.
  • Support models like "grok-3" for general reasoning and "grok-3-mini" for lightweight, high-speed tasks.
  • Handle requests with JSON payloads, including parameters for temperature (0.0-2.0), max tokens (up to 4096), and stop sequences.
  • Provide OpenAI-like responses, including choices array with text and usage stats.
  • Authenticate via API key in the Authorization header as "Bearer $XAI_API_KEY".

Usage Patterns

To use this skill, set the API key in your environment (e.g., export XAI_API_KEY=your_key), then make HTTP requests to api.x.ai/​v1. Structure requests as POST calls with JSON bodies. For chat interactions, specify the model and messages array. Always include error checking in your code loops. If using in a script, handle retries for rate limits. For asynchronous patterns, use webhooks or polling on response IDs.

Common Commands/​API

  • Endpoint for chat completions: POST https://api.x.ai/v1/chat/completions
    • Required headers: Authorization: Bearer $XAI_API_KEY, Content-Type: application/​json
    • Example body: {"model": "grok-3", "messages": [{"role": "user", "content": "Explain quantum computing"}]}
    • CLI command: curl -X POST -H "Authorization: Bearer $XAI_API_KEY" -H "Content-Type: application/​json" -d '{"model":"grok-3","messages":[{"role":"user","content":"Summarize this text"}]}' https://api.x.ai/v1/chat/completions
  • Endpoint for model info: GET https://api.x.ai/v1/models
    • Query params: None required; returns available models like grok-3 and grok-3-mini.
    • CLI command: curl -H "Authorization: Bearer $XAI_API_KEY" https://api.x.ai/v1/models
  • Common flags in requests: Add "temperature": 0.7 for creativity, or "max_tokens": 150 to limit output length.
  • Config format: Store settings in a JSON file, e.g., {"api_key": "$XAI_API_KEY", "default_model": "grok-3-mini"} and load it in code.

Integration Notes

Integrate by setting $XAI_API_KEY as an environment variable before runtime. In Python, use requests library: import os; api_key = os.environ.get('XAI_API_KEY'). For Node.js, use fetch with headers. Avoid hardcoding keys; use secure vaults. If proxying requests, ensure HTTPS passthrough. Test with a simple script first, and handle rate limits by checking response headers for X-RateLimit-Remaining. For embedding, map xAI models to OpenAI formats in your codebase.

Error Handling

Check HTTP status codes: 401 for invalid API key (retry with correct $XAI_API_KEY); 429 for rate limits (implement exponential backoff, e.g., wait 5 seconds then retry). Parse JSON errors for messages like "context_length_exceeded" and truncate input accordingly. In code, wrap requests in try-except blocks: try: response = requests.post(url, headers=headers, json=data) except requests.exceptions.RequestException as e: log_error(e) and raise. For model-specific errors, validate inputs before sending, e.g., ensure messages array is not empty.

Concrete Usage Examples

  1. Generate a text summary: Use this to summarize content quickly. Code snippet: import requests; os.environ['XAI_API_KEY'] = 'your_key'; response = requests.post('https://api.x.ai/v1/chat/completions', headers={'Authorization': 'Bearer ' + os.environ['XAI_API_KEY']], json={'model': 'grok-3-mini', 'messages': [{'role': 'user', 'content': 'Summarize AI ethics'}]}); print(response.json()['choices'][0]['message']['content'])
  2. Perform reasoning task: Query for problem-solving. Code snippet: import requests; response = requests.post('https://api.x.ai/v1/chat/completions', headers={'Authorization': 'Bearer $XAI_API_KEY'}, json={'model': 'grok-3', 'messages': [{'role': 'user', 'content': 'Solve: What is 15% of 200?'}], 'temperature': 0.2}); print(response.json()['choices'][0]['message']['content'])

Graph Relationships

  • Belongs to cluster: ai-apis
  • Tagged with: ai-apis, xai
  • Related via embedding hint: xai-grok (links to ai-apis cluster)

More skills from alphaonedev

auto-updater-skill logo
alphaonedev/openclaw-graph

auto-updater-skill

Automatic skill update management: check for updates, diff, apply, rollback, version tracking

0 0
View
nano-banana-pro logo
alphaonedev/openclaw-graph

nano-banana-pro

Gemini image generation/editing: Imagen 3, edit regions, style transfer, upscaling

0 0
View
macos-keychain logo
alphaonedev/openclaw-graph

macos-keychain

Keychain: security CLI, API key storage, certificates, codesigning, Secure Enclave

0 0
View
k8s logo
alphaonedev/openclaw-graph

k8s

Expertise in orchestrating and managing containerized applications at scale using Kubernetes.

0 0
View
clawhub logo
alphaonedev/openclaw-graph

clawhub

ClaWHub skills marketplace: browse, search, install, rate, review skills. https://clawhub.com

0 0
View
aws-vpc logo
alphaonedev/openclaw-graph

aws-vpc

Manage and configure Amazon Virtual Private Cloud for creating isolated, customizable network environments in AWS.

0 0
View
session-mesh logo
alphaonedev/openclaw-graph

session-mesh

Session topology: discover alive sessions, specialization registry, steer/kill sub-agents, session keys

0 0
View
aws-ec2 logo
alphaonedev/openclaw-graph

aws-ec2

Manage and configure Amazon EC2 instances for scalable virtual servers and cloud computing resources.

0 0
View
node-ops logo
alphaonedev/openclaw-graph

node-ops

Node pairing: approve/reject, nodes run/invoke, screen_record, camera_snap, location, System76 mgmt

0 0
View
grafana logo
alphaonedev/openclaw-graph

grafana

Grafana is an open-source tool for creating dashboards to visualize and query metrics, logs, and traces from various dat

0 0
View
unity-xr logo
alphaonedev/openclaw-graph

unity-xr

Develops XR applications using Unity for AR and VR, focusing on immersive interactions and cross-platform compatibility.

0 0
View
coding-r logo
alphaonedev/openclaw-graph

coding-r

R: data frames, tidyverse, ggplot2, statistical modeling, RMarkdown, Shiny, package development

0 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View