Independent guide. Not affiliated with SpaceXSI, xAI or X.
Home/Grok API
Grok API for developers

Grok API: keys, endpoints, models and a first request

How developers get access to Grok models, which endpoints and SDKs to use, and what the current model line-up costs.

Checked October 18, 2026By GrokMag editorsIndependent · not affiliated with SpaceXSI, xAI or X
Short answer

The Grok API is the paid developer interface from SpaceXSI (formerly xAI), served at https://api.x.ai/v1. You create an account at console.x.ai, buy prepaid credits and generate a key. The flagship grok-4.7 has a 500k-token context window and costs $2 per 1M input tokens and $6 per 1M output tokens.

What the Grok API is

The Grok API is the paid developer interface from SpaceXSI (formerly xAI). It gives your own code access to the same Grok model family that powers the Grok apps, plus image, video and voice models. You pay per token, per image, per second of video or per minute of audio.

The API is separate from the consumer plans. The X Subscription pricing page lists “Grok API access” under Plus, but it also says API usage is billed separately. SpaceXSI does not explain how the two interact, so plan on paying for API calls through console credits.

The main use cases are the usual ones: chat and reasoning in your own apps, agents that call tools, document and image understanding, and media generation. For a plain definition, see the API entry in our glossary.

How to get a Grok API key

SpaceXSI’s quickstart describes four steps:

  1. Create an account at console.x.ai.
  2. Load prepaid credits. The docs say credits are required before calls work.
  3. Open the API Keys page and generate a key.
  4. Store the key as an environment variable named XAI_API_KEY, not in your source code.

Billing is prepaid by default. When credits run out, requests are rejected. You can turn on auto top-up, which has a $5 minimum. Invoiced billing is off by default and must be requested from SpaceXSI sales.

Free credits: The official quickstart, billing and pricing pages list no free or signup credits. SpaceXSI’s enterprise FAQ says it “may offer free credits” in exchange for permission to train on your data. Third-party sites describe a data-sharing program with monthly credits, but we could not confirm its current amount or status on an official page. Check your console before you count on it.

Base URL, SDKs and endpoints

All requests go to the base URL https://api.x.ai/v1. The docs list three ways to call it:

  • xai_sdk, the official Python SDK.
  • The OpenAI SDK (Python and JavaScript), pointed at the xAI base URL.
  • The Vercel AI SDK, through the @ai-sdk/xai package.

Responses API or Chat Completions

The Responses API at /v1/responses is SpaceXSI’s main surface. Chat Completions at /v1/chat/completions is still supported. With Grok 4.7, Responses API calls always return encrypted reasoning. The legacy /v1/completions endpoint is replaced by /v1/chat/completions.

Anthropic-style endpoints are deprecated

The Anthropic-compatible /v1/messages and /v1/complete endpoints are marked deprecated. SpaceXSI points users to the Responses API or gRPC instead. No sunset date is given, but new projects should not build on them.

US regional endpoint

A US endpoint at https://us.api.x.ai/v1 keeps inference in the United States. It costs 1.1x global rates and only serves grok-4.7 and grok-4.6. Details are on our Grok API pricing page.

A minimal first request

This example calls the Responses API with curl. It assumes your key is stored in XAI_API_KEY:

curl https://api.x.ai/v1/responses -H "Authorization: Bearer $XAI_API_KEY" -H "Content-Type: application/json" -d '{"model": "grok-4.7", "input": "Explain a context window in one sentence."}'

Two settings are worth knowing from day one:

  • reasoning_effort: Grok 4.7 accepts low, medium, high (the default) or xhigh.
  • prompt_cache_key (or the x-grok-conv-id header): SpaceXSI strongly recommends setting one. Without it, a request can land on a cache-cold server and pay the full input price.

Field names can change. Check the request reference in the official docs before you ship.

Models on the Grok API

These are the current text models, with prices in USD per 1M tokens. Prompts over 200k tokens cost double.

ModelContextInput / outputNotes
grok-4.7500k$2.00 / $6.00Flagship, released Sep 21, 2026. Text and image input.
grok-4.6500k$2.00 / $6.00Released Aug 12, 2026.
grok-4.5500k$2.00 / $6.00Trained alongside Cursor.
grok-4.31M$1.25 / $2.50Largest window. Batch discount.
grok-4.20-0309 (reasoning, non-reasoning, multi-agent)1M$1.25 / $2.50Multi-agent version runs several agents on one task.
grok-build-0.1256k$1.00 / $2.00Coding model behind Grok Build.

Grok 4.7 Fast is not on the public API. It is only offered in Cursor and Grok Build. Several older models, including grok-3, grok-4-0709, Grok 4 Fast and grok-code-fast-1, were retired on May 15, 2026. Calls to grok-code-fast-1 now route to grok-build-0.1.

The API also serves the Grok Imagine image and video models and the Grok Voice models. See Grok Imagine and the Grok Voice API guide.

Built-in tools

Grok models can call server-side tools that SpaceXSI runs for you. The pricing page lists:

  • Web Search and Image Search.
  • X Search, which returns posts and profiles from X.
  • Code Execution.
  • File attachment search and Collections Search for retrieval over your own documents.
  • view_image, view_x_video and Remote MCP tools, which are charged for tokens only.

Most tools are billed per 1,000 calls on top of token costs. Each model also has per-tier request and token caps, covered on our Grok API rate limits page.

Questions people ask

Is the Grok API free?

No. SpaceXSI’s official pages list no free signup credits, and calls need prepaid credits. A data-sharing credit program is described by third-party sites only. See Grok API pricing.

Is the Grok API compatible with the OpenAI SDK?

Yes. SpaceXSI lists the OpenAI SDK for Python and JavaScript as a supported way to call the API. You point it at the base URL https://api.x.ai/v1 and use your xAI key.

Can I still use Anthropic-style endpoints with Grok?

The /v1/messages and /v1/complete endpoints still exist but are deprecated. SpaceXSI recommends the Responses API or gRPC instead.

What is the newest model on the Grok API?

grok-4.7, released September 21, 2026, with a 500k context window and a May 2026 knowledge cutoff. Grok 4.8 has not been released as of October 18, 2026.