Back to All Cheatsheet Libraries cheatsheets

Grok

Chat modes, real-time X integration, and image generation reference for xAI's Grok.

xAI's model family, with a live feed attached

Grok's distinguishing feature isn't raw capability so much as real-time access to X. For questions about what's happening right now — breaking events, live sentiment, an unfolding story — it has a data source the others don't.

That's also its main caveat: X is an unfiltered source. Grok will confidently relay what's being posted, which is not the same as what's true.

Model ID Context Notes Input / M
grok-4.6500kCurrent flagship. Knowledge cutoff 1 February 2026.$2.00–$4.00
grok-4.5500kPrevious flagship, same price band.$2.00–$4.00
grok-4.31MLarger context, cheaper — good for long-document work.$1.25–$2.50
grok-4.20-0309-reasoning1MExplicit reasoning variant. Slower, better on multi-step problems.$1.25–$2.50
grok-4.20-0309-non-reasoning1MSame model without the reasoning pass — faster and cheaper per answer.$1.25–$2.50
grok-4.20-multi-agent-03091MMulti-agent variant.$1.25–$2.50
grok-build-0.1256kBuild/coding-oriented model.$1.00–$2.00
grok-imagine-image-2.0Image generation.$0.04 / image
grok-imagine-video-1.5Video generation.$0.08 / second
Voice service Price
Speech to speech (grok-voice-think-fast-2.0)$0.08 / minute of audio
Speech to text$0.10 / hour
Text to speech$15.00 / 1M characters
Choosing a model
  • General work: grok-4.6. Newest, and the one the chat product uses.
  • Long documents or large codebases: grok-4.3 — 1M context at half the input price of the 4.5/4.6 band.
  • Multi-step problems: the -reasoning variant. For everything else the -non-reasoning one is faster and cheaper, and reasoning tokens are billed.
  • Coding: grok-build-0.1 is purpose-built and the cheapest text tier, though only 256k context.
  • Prices show a range — check the live models page for which tier applies to your account and region.

OpenAI-compatible, so migration is a two-line change

The xAI API mirrors OpenAI's shape. In most codebases you change the base URL and the API key and everything else keeps working — which is the point.

# Python — the OpenAI SDK, pointed at xAI from openai import OpenAI client = OpenAI( api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1", ) resp = client.chat.completions.create( model="grok-4.6", messages=[ {"role": "system", "content": "You are a concise technical assistant."}, {"role": "user", "content": "Explain CAP theorem in three sentences."}, ], temperature=0.2, ) print(resp.choices[0].message.content) # Streaming stream = client.chat.completions.create( model="grok-4.6", messages=[{"role": "user", "content": "Write a haiku about pagers."}], stream=True, ) for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") # curl curl https://api.x.ai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $XAI_API_KEY" \ -d '{ "model": "grok-4.6", "messages": [{"role": "user", "content": "Summarise this in one line."}] }'
Practical notes
  • Keys come from the xAI console. Never put one in client-side code — anything in a browser bundle is public.
  • Function calling and structured output follow the OpenAI shapes, so existing tool definitions largely port across.
  • Reasoning models bill their reasoning tokens as output. A cheap-looking request can cost several times what you expect.
  • Set temperature low (0–0.3) for anything factual or code-generating; the default is tuned for conversation.
  • Streaming matters for perceived latency on the big-context models.
  • Rate limits and concurrency vary by tier — handle 429s with backoff rather than assuming headroom.
Where Grok earns its place
  • Live events. The X integration makes it the strongest option for "what is happening right now" — an ongoing outage, a breaking story, live reaction.
  • Sentiment on a topic. It can summarise what's actually being said about something, which no static-corpus model can do.
  • Long context. 500k–1M windows handle whole codebases and large document sets without chunking.
  • Voice. Speech-to-speech at $0.08/minute is competitive for building conversational interfaces.
  • Available through grok.com, the X apps, and the API. The chat product and the API expose different feature sets.
Prompting
  • Say explicitly when you want current information — otherwise it may answer from training data with a February 2026 cutoff.
  • Ask for sources on anything drawn from X, then check them. A post is evidence that someone said a thing, not that it's true.
  • Use a system prompt to set format and tone. Grok's default voice is deliberately informal and often not what you want in a product.
  • For factual work, ask it to say when it doesn't know rather than to guess.
  • Long context is not free attention — put the important material near the start or end of a very large prompt.

Gotchas

Worth knowing before you rely on it
  • The X feed is a source, not a fact-checker. Real-time access means real-time access to whatever is being posted, including coordinated and mistaken claims. Verify anything consequential.
  • Knowledge cutoff for grok-4.6 is 1 February 2026. Without an explicit request for current information you may get training-data answers presented confidently.
  • Reasoning tokens are billed as output. The reasoning variants can cost markedly more per request than the sticker price suggests.
  • Grok's default persona is informal and edgier than other assistants. Fine in chat, usually wrong for a customer-facing product — constrain it in the system prompt.
  • Model IDs change often and older ones get retired. Pin a specific ID in production and watch the changelog rather than tracking "latest".
  • Chat-product features and API features are not the same set. Something you saw in the app may not be exposed via the API.
  • Prices are shown as ranges. Confirm your actual rate in the console before budgeting.
  • As with any model, don't paste secrets or personal data into prompts, and check the data-retention terms for your tier.

Tips

Two-line migration

Point the OpenAI SDK at https://api.x.ai/v1 with an xAI key. Everything else in an existing integration generally works unchanged — easy to A/B against another provider.

Match the model to the job

grok-4.3 gives you 1M context at roughly half the input price of the 4.6 band. For bulk document work that difference compounds fast.

Skip reasoning when you don't need it

The explicit -non-reasoning variant is faster and avoids paying for reasoning tokens on tasks that don't benefit.

Always ask for citations

On anything sourced from X, request links. It turns an unverifiable claim into something you can check in ten seconds.

Drop the temperature

0–0.3 for factual answers, extraction, and code. The conversational default introduces variance you don't want in a pipeline.

Pin the model ID

Dated IDs like grok-4.20-0309-reasoning are stable. Tracking a moving alias means your output changes without a deploy.

Resources