The xAI API exposes Grok models, media generation and server-side tools through a developer account. Use this hub to connect the right interface with its billing rules, team controls and practical first request.
What xAI offers through the API
xAI’s developer platform spans text generation, Imagine media services and Voice. These capabilities have separate request surfaces and usage units. Begin by choosing the output your application needs; a text model entry is not a substitute for an image or speech-generation endpoint. Official documentation.
Map the complete workflow before choosing a model. A document assistant needs retrieval, an answer and evidence that supports it. A coding workflow needs a proposed change and a way to evaluate that change. A media workflow needs an asset that meets the requested properties. Keep the model’s generation step separate from the application’s decisions about whether the result is acceptable.
The current quickstart demonstrates the Responses endpoint at https://api.x.ai/v1/responses and the native xai-sdk Python client. An OpenAI-compatible client is another documented option when configured with the xAI base URL and key. Official documentation.
Choose one interface for your baseline and retain the smallest working example. A migration becomes harder to assess if it simultaneously changes the endpoint, model, message construction and error wrapper. Keep a saved set of tasks and expected properties, then introduce each new capability with an explicit reason.
The native Python client uses gRPC and provides chat helpers such as chat.create, append and sample. Its timeout and exception behavior differ from those of a generic REST client. That distinction matters when translating an HTTP troubleshooting example into native SDK code. Official documentation.
Account ownership is part of a reliable integration. Identify the team that pays for a request, the person who can restrict credentials and the operator who responds to spending changes. Use purpose-specific keys and keep deployment configuration separate from experimental notebooks. A working request should be traceable without exposing its credential.
xAI documents server-side search tools. Fresh retrieval is an explicit tool choice; the model’s name alone does not establish access to current information. Inspect the returned citations and actual tool usage before presenting an answer as grounded in a retrieved source. Official documentation.
For a first evaluation, disable optional tools and request a small text response. Establish that the credential, model and response parser work together. Add retrieval, structured output or media only after that baseline is clear. Record what changed and judge the result against the original task, not only whether the request returned successfully.
Per-request cost tracking is exposed with the response. The native client offers a convenience cost property, while REST responses include an integer cost field in usage. Preserve those observations when evaluating a multi-step application so spending can be attributed to completed work. Official documentation.
The sections below link the operating reference: pricing for charge conditions, models for identifiers, keys for console setup, limits for traffic planning and errors for diagnosis. Use them together when deciding whether a prototype can become a maintained service.
Pricing at a glance
| Summary | Verified value |
|---|---|
| Lowest input price model | grok-build-0.1 |
| Input price | $1 per 1M tokens |
| Output price | $2 per 1M tokens |
| Free access | No universal ongoing free inference allowance was established in the last successful check. |
Last verified · Source ↗
Text rates distinguish ordinary input, cached input and output, with context-dependent conditions for applicable models. Tool and media operations have their own charges. Official documentation.
Read the xAI pricing explanation before comparing a token-only estimate with a full agent workflow.
Models available
| Model | Official identifier | Modalities | Context tokens | Input USD / 1M | Output USD / 1M | Status |
|---|---|---|---|---|---|---|
| grok-4.20-0309-non-reasoning | grok-4.20-0309-non-reasoning | text, image | 1,000,000 | $1.25 | $2.5 | Active |
| grok-4.20-0309-reasoning | grok-4.20-0309-reasoning | text, image | 1,000,000 | $1.25 | $2.5 | Active |
| grok-4.20-multi-agent-0309 | grok-4.20-multi-agent-0309 | text, image | 1,000,000 | $1.25 | $2.5 | Active |
| grok-4.3 | grok-4.3 | text, image | 1,000,000 | $1.25 | $2.5 | Active |
| grok-4.5 | grok-4.5 | text, image | 500,000 | $2 | $6 | Active |
| grok-4.6 | grok-4.6 | text, image | 500,000 | $2 | $6 | Active |
| grok-build-0.1 | grok-build-0.1 | text, image | 256,000 | $1 | $2 | Active |
Last verified · Source ↗
Use the Grok model reference to inspect exact identifiers, modalities and lifecycle notes. A display label should never be turned into a guessed request value.
Free tier and how to get a key
The official billing documentation was checked. No universal ongoing free inference allowance was established by that source. Promotional or account-specific credits require a check in your account. Read the official terms ↗
Last verified · Source ↗
The console’s billing documentation centers on team credits and invoiced billing. Check the actual team offer before assuming free API access. Official documentation.
Follow xAI key creation and the free-access checks before running unattended calls.
Rate limits and tiers
Team capacity is model-specific and includes short-window request enforcement alongside token limits. Budget and throughput are separate operating controls. Official documentation.
Open xAI rate limits when planning bursts or background jobs.
Service status
Check the xAI errors guide for a request-specific problem. A public service indicator cannot establish that a particular team or key has permission.
Start in 5 minutes
import os
from xai_sdk import Client
from xai_sdk.chat import user
client = Client(api_key=os.environ["XAI_API_KEY"], timeout=60)
chat = client.chat.create(model="grok-4.6")
chat.append(user("Describe a useful model API application in one sentence."))
response = chat.sample()
print(response.content)
Run the native xAI Python tutorial for explicit timeout handling and an intentionally invalid model. The example is source code, not a claimed successful inference transcript.
Recent changes
- xAI · grok-build-0.1 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.6 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.5 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.3 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.20-multi-agent-0309 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.20-0309-reasoning — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.20-0309-non-reasoning — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-build-0.1 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.6 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
- xAI · grok-4.5 — MetadataRecord updated; consult the linked source for details. → Record updated; consult the linked source for details.Source ↗
Review observed changes before replacing a pinned model or revising a budget. Keep a copy of the source and your workload assumptions when approving an operational change.
Use the AI API cost calculator to turn the model and workload you are considering into an estimate.
Last verified · Source ↗
Frequently asked questions
Does a Grok model automatically search current information?
Can I use an OpenAI-compatible client?
Why do native SDK errors look unlike HTTP errors?
What account owns an API key?
Where can I inspect actual request cost?
Sources
Last verified · Source ↗