xai-api

Call the xAI API from server code for chat, image and video generation, and text-to-speech.

Updated Sep 17, 2026
One-click install
npx skills add https://github.com/scomofo/midi-stage2 --skill xai-api-scomofo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: xai-api
Source: https://github.com/scomofo/midi-stage2/tree/main/.grok/skills/xai-api
Command: npx skills add https://github.com/scomofo/midi-stage2 --skill xai-api-scomofo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? This Skill lets your app use real xAI (Grok) API capabilities through the injected XAI_API_KEY environment variable, so you can add chat, image/video generation, and voice features without mocking responses or integrating another provider. ## Core Features & Use Cases - Chat / LLM: Call the OpenAI-compatible chat completions endpoint with the latest grok-4.5 model from server functions using plain fetch. - Imagine (Image & Video): Generate and edit images and generate short video clips at runtime inside the running app. - Voice (TTS): Convert text to spoken audio with expressive voices, plus transcription support. - Use Case: Add an AI assistant to your app by creating a server function that reads process.env.XAI_API_KEY, posts to https://api.x.ai/v1/chat/completions, and returns the response text to the client. ## Quick Start Add a server function that calls the xAI chat completions endpoint with the injected XAI_API_KEY and wire it to a button in the app.

Frequently Asked Questions about xai-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call the xAI API from a TanStack Start app?▼

Create a server function with createServerFn, read process.env.XAI_API_KEY, and POST to https://api.x.ai/v1/chat/completions with an Authorization Bearer header. The API is OpenAI-compatible, so standard chat completion request shapes work.

What model should I use for xAI chat completions?▼

Default to grok-4.5, the latest model, unless the user asks otherwise. The endpoint accepts OpenAI-style messages arrays, and streaming, structured outputs, and vision follow the same compatible shapes documented at docs.x.ai.

Can I generate images and video with the xAI API at runtime?▼

Yes, POST to /v1/images/generations with model grok-imagine-image-quality or grok-imagine-image, use /v1/images/edits for natural-language edits, and use grok-imagine-video via async video endpoints for clips up to about 15 seconds.

Why is XAI_API_KEY undefined in my app?▼

The key is injected by the platform but can be absent because rollout is gated. Check for it before calling and show a friendly unavailable state instead of crashing, and never create a .env file or expose it via VITE_-prefixed variables.

Can I call the xAI API from browser client code?▼

No, the key is server-only. Calling from the browser would expose the app owner's personal key. Always call from createServerFn handlers or server code and serve results, including TTS audio bytes, to the client.

How do I avoid burning xAI API quota in a deployed app?▼

Make calls user-initiated rather than on page load or keystroke, cap output with max_tokens, cache or persist results instead of regenerating, gate expensive media generation behind auth when available, and retry at most once on errors.