CreateWithAIHub

API / SDK SpaceXSI (xAI)

xAI API

xAI's (now SpaceXSI) OpenAI-compatible API for Grok text, image, video and voice models, with Python and TypeScript SDKs.

Visit website ↗
Save

What it is

The xAI API (called the SpaceXSI API in newer docs) serves Grok models at api.x.ai through Responses, Chat Completions, Images, Videos, Voice, Files, Batches and Models endpoints, and states compatibility with the OpenAI REST API. Server-side tools add web search, X search, code execution and collections search. Official SDKs exist for Python (gRPC-based) and TypeScript, and the docs also show the OpenAI SDKs and the Vercel AI SDK provider.

What it's useful for

Switching an existing OpenAI SDK integration to Grok by changing the base URL, or generating images and videos from a backend.

Key features

  • Responses and Chat Completions endpoints, compatible with the OpenAI REST API
  • Image and video generation and editing endpoints (Grok Imagine)
  • Voice API for speech-to-speech, speech-to-text and text-to-speech
  • Server-side Web Search, X Search, code execution and remote MCP tools
  • Batch API at 20% off standard rates for Grok 4.x models
  • Official xai-sdk (Python) and TypeScript SDKs, Apache-2.0

How to use it

Before you start

  • console.x.ai account with credits
  • API key (XAI_API_KEY)
Python SDK
pip install xai-sdk
Vercel AI SDK provider
npm install ai @ai-sdk/xai zod
OpenAI SDK (Python)
pip install openai

Commands are copied from the official documentation. Check the docs for the latest version before running them.

Limitations to know

  • Usage is prepaid: the account must be loaded with credits before making requests
  • Server-side tools are billed per call on top of token costs
  • Not every model accepts Batch API requests

Website tech stack

Hosting & CDN
Cloudflare
Framework
Next.js
Analytics
Google Analytics, Google Tag Manager

Detected on x.ai on 25 Nov 2026. This describes the public website only; the product itself may use different technology.

Alternatives

Cohere's API for Command chat models, Embed and Rerank, with official Python, TypeScript, Java and Go SDKs and free trial keys.

Free plan + paid

Anthropic's REST API for Claude models, with official SDKs in Python, TypeScript, Go, Java, C#, PHP and Ruby.

Paid

OpenAI's developer API for GPT, image, audio and embedding models, with official SDKs in several languages.

Paid

Mistral AI's pay-as-you-go API for chat, code completion, OCR, embeddings, audio and agents, with Python and TypeScript SDKs.

Paid

See all 5 xAI API alternatives →

MCP servers for this

Browserbase's hosted MCP server that lets agents drive cloud browsers with natural-language Stagehand actions.

Free plan + paid

Google Chrome team's MCP server and CLI that let coding agents control, debug and profile a live Chrome browser.

FreeOpen source

Docker Desktop's MCP Toolkit and Catalog that run MCP servers in containers and connect them to clients through one gateway.

Free plan + paidOpen source

Skills for this

Anthropic skill that guides Claude through designing, building and evaluating MCP servers in TypeScript or Python.

FreeOpen source

Related resources

Cerebras' cloud API for very fast inference on open-weight models, with an OpenAI-compatible endpoint and per-token pricing.

Paid

Cognition's autonomous software engineering agent that works in a cloud VM and opens pull requests.

Free plan + paid

Open-source sandboxes for AI agents: isolated Firecracker microVMs you start and control from a Python or JavaScript SDK.

FreeOpen source

Z.ai's GLM model family (GLM-5.3, GLM-5.3-Flash): open-weight MoE language models with a 1M-token context, API and chat app.

Free plan + paid

Type to search. Use ↑ ↓ and Enter.