Get started with SpaceXAI

Intelligent, fast, and cost-effective models across code, text, voice, image, and video.

import { xai } from "@ai-sdk/xai";
import { generateText } from "ai";

const { text } = await generateText({
  model: xai.responses("grok-4.7"),
  prompt: "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",
});

console.log(text);

Models

Grok 4.7

New
grok-4.7

Our flagship model for code and everything else: agentic tool calling, minimal hallucinations, configurable reasoning.

Context
500k tokens
Input
$2.00 / 1M tokens
Output
$6.00 / 1M tokens
Reasoning
Configurable

Voice API

Real-time conversations, speech-to-text, and text-to-speech.

STS
$0.08 / min
TTS
$15.00 / 1M chars
STT (Batch)
$0.10 / hour
STT (Streaming)
$0.20 / hour

Imagine API

Turn ideas into reality with image and video generation.

Modes
Generation & editing
Speed
Industry-leading
Image · 1K / 2K
Starting at $0.02 / image
Video · 480p / 720p / 1080p
Starting at $0.02 / sec

Jump straight in

Try code, text, voice, image, and video models below

import { xai } from "@ai-sdk/xai";
import { generateText } from "ai";

const { text } = await generateText({
  model: xai.responses("grok-4.7"),
  prompt: "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",
});

console.log(text);

Responses API

Agentic coding with Grok Build on the API—refactor, debug, and build in your own tools.

  • Agentic coding
  • IDE & tool integrations
  • Powers Grok Build
  • $2.00 / 1M input tokens
  • $6.00 / 1M output tokens

Explore the documentation