Grok 2 api
★★★★ 4.3 CE

Grok 2 API: Access, Rate Limits & SDKs 2026

The xAI API is OpenAI-compatible and built around one differentiator: server-side Web Search and X Search give Grok live web and X data most rivals lack.

Grok 2 API verdict

Verified today·5 sources checked

The xAI API authenticates with a single bearer key and is OpenAI-compatible.

The native xai-sdk, the OpenAI SDK pointed at https://api.x.ai/v1, or the Vercel AI SDK all call grok-4.3. A grok-build-0.1 model covers coding, and separate Voice and Imagine APIs handle speech and image or video.

How to build on it

xAI's API is a low-friction OpenAI-compatible target with one differentiator worth building around. Server-side Web Search and X Search give grok-4.3 live web and X data that most rivals lack, so it is a strong backend for realtime, current-events and social-listening apps. Keep your OpenAI SDK and swap the base URL to https://api.x.ai/v1, or use the native xai-sdk or Vercel AI SDK for an automatic tool loop. Lean on function calling with Pydantic or Zod schemas, up to 200 tools and parallel by default, and pin a model alias for reproducibility or use -latest for new features. Budget on competitive token pricing, at $1.25 and $2.50 with an 84% cache discount. Remember the base model needs the search tools for recency, and that logprobs are unsupported on current models.

Honest limits
  • The base model has no realtime knowledge beyond training data unless server-side Web Search or X Search tools are enabled.
  • logprobs and top_logprobs are unsupported on grok-4.20 and newer, and are silently ignored if set.
  • A tool whose parameters root is not an object, or a union of objects, cannot be compiled and is rejected with a 400 that names the tool. Max 200 tools per request.
  • With streaming, a function call is returned whole in a single chunk rather than streamed across chunks, so parse it as one unit.
Auth
Bearer XAI_API_KEY
Base URL
api.x.ai/v1 (OpenAI-compat)
Built-in tools
Web Search + X Search
Tools/request
Max 200
Context
1M tokens
View sources

Build with the Grok 2 API

Your first Grok 2 API request

POST /v1/chat/completionsbash
curl https://api.x.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${XAI_API_KEY}" \
  -d '{
    "model": "grok-4.3",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

How to authenticate with the Grok 2 API

AspectDetailNotes
AuthBearer XAI_API_KEYManage keys in the xAI API console
Base URLhttps://api.x.ai/v1 (OpenAI-compatible)Drop-in for the OpenAI SDK
SDKsxai-sdk (Python, JS), OpenAI SDK, Vercel AI SDK@ai-sdk/xai for the Vercel AI SDK
Primary modelgrok-4.3Most intelligent and fastest; 1M context
Coding modelgrok-build-0.1256k context, agentic coding workflows
Model aliases<name>, <name>-latest, <name>-<date>Auto-migrate or pin a release
Other APIsVoice API, Imagine API (image + video)Voice $3/hr agent; image $0.02/image

Core endpoints and tools

CapabilityHowPurpose
Responses APIGenerate, multi-turn, function callingText generation and conversations
Function callingtools[] with name, description, JSON schemaCustom tools the model invokes; you execute and return
Built-in toolsweb_search(), x_search()Realtime web and X data, executed on xAI servers
Tool choiceauto / required / none / forcedControl whether and which tool the model calls
Parallel tool callsEnabled by defaultMultiple tool calls in one response; disable with parallel_tool_calls:false
Structured outputsStructured outputs featureJSON conforming to a schema
Batch APIBatch APIAsynchronous high-volume jobs
Image inputjpg/png, up to 20MiB, no count limitMultimodal prompts; any text/image order

Limits, aliases and model rules

LimitDetailNotes
Context window1M tokens (grok-4.3)256k for grok-build-0.1
Tools per requestMax 200 toolsInvalid tool schema rejected with 400 naming the tool
Image inputjpg/png, up to 20MiB, no count limitAny text/image order accepted
Realtime dataNone without search tools enabledEnable Web Search / X Search for live data
logprobsNot supported on grok-4.20 and newerSilently ignored if set
Role orderNo role-order limitationMix system/user/assistant in any sequence
Tool schema rootMust be an object or union of objectsScalar/array root rejected with 400

SDKs, tools and developer fit

AspectDetailNotes
SDKsxai-sdk (Python/JS), OpenAI SDK, Vercel AI SDKOpenAI-compatible via base_url swap
Tool schemasJSON Schema or Pydantic / Zodmodel_json_schema() generates the schema
Built-in vs customBuilt-in run on xAI servers; custom pause for youweb_search/x_search auto, custom returns tool_call
Streaming tool callsFunction call returned whole in one chunkNot streamed across chunks
Vercel AI SDKxai.responses('grok-4.3') with auto tool loopstreamText + tool() + stepCountIs
Other surfacesVoice API (STT/TTS), Imagine API (image/video)Dedicated models per modality
API pricing (grok-4.3)$1.25/1M in, $2.50/1M out, cache hit $0.20/1MIndependent cross-reference

Grok 2 API FAQ

How do I authenticate with the xAI API?

Create a key in the xAI API console and send it as a bearer token, as Authorization: Bearer ${XAI_API_KEY}. The native xai-sdk reads the XAI_API_KEY environment variable automatically. The API is OpenAI-compatible, so you can keep the OpenAI SDK and point its base URL at https://api.x.ai/v1, then call model grok-4.3.

Can I use the OpenAI SDK or Vercel AI SDK with Grok?

Yes. xAI ships a native xai-sdk for Python and JavaScript, and is OpenAI-compatible through the OpenAI SDK with base URL https://api.x.ai/v1. The Vercel AI SDK also supports it through @ai-sdk/xai, with an automatic tool loop. Tool parameter schemas can be plain JSON Schema, Pydantic models, or Zod.

How does Grok get realtime data?

The base model has no knowledge of current events beyond its training data. To use live information, enable the built-in server-side tools web_search and x_search, which run on xAI servers and fetch live web and X content during the request. Built-in tools execute automatically, while your custom function tools pause execution and return a tool_call for you to handle.

What are the xAI API limits?

The hard ceilings are a 1M-token context, 256k for grok-build-0.1, and a maximum of 200 tools per request. Images must be jpg or png up to 20MiB, with no count limit and any text or image order. A tool whose parameters root is not an object or union of objects is rejected with a 400 that names the tool, and logprobs and top_logprobs are unsupported on grok-4.20 and newer.

What can the xAI API do beyond text, and how is function calling structured?

Beyond the Responses API, which handles text, multi-turn and function calling, xAI offers a Voice API for STT, TTS and real-time conversations, and an Imagine API for image and video generation. Function calling defines tools by name, description and JSON-schema parameters. Tool choice can be auto, required, none or a forced function. Parallel tool calls are on by default and disabled with parallel_tool_calls:false, and with streaming a function call is returned whole in a single chunk.

Sources & verification

Verified by ComparEdgeMethod: Vendor docs, official pages, and selected independent sources
SourceWhat was checkedLast checked
X GrokOfficial product pageJuly 10, 2026
Artificial AnalysisIndependent referenceJuly 10, 2026
X Developer docsOverviewJuly 10, 2026
X Developer docsDevelopers ModelsJuly 10, 2026
X Developer docsTools Function CallingJuly 10, 2026

Every fact on this Grok 2 page is tied to a named source and a verification date. Freshness-sensitive figures trace to the sources above; verify against the vendor before relying on them.