Multimodal model API platform
How to use
xAI API.
Building Grok-powered text, coding, reasoning, multimodal, media, realtime voice, retrieval, and tool-using applications through production APIs.
xAI API is a developer platform for Grok text, reasoning, vision, image, video, voice, realtime, retrieval, and tool-using applications. Building Grok-powered text, coding, reasoning, multimodal, media, realtime voice, retrieval, and tool-using applications through production APIs. This guide covers the whole path in one place: official access, a first session that produces something reviewable, the checks that make output trustworthy, and the permissions worth limiting before you connect real work.
AI should make the work easier to inspect. If the workflow removes the source, the owner, or the review step, redesign the workflow.
Access & setup
Find, install, and sign in to xAI API
Get into the official xAI API experience with the right account and a setup you understand.
- 01
Start at https://console.x.ai/ and confirm the domain before entering account or payment information.
- 02
Availability: The xAI API is managed through the browser-based xAI Console and accessed from server applications through REST, the xAI SDK, OpenAI-compatible clients, and supported JavaScript libraries.
- 03
An xAI account and funded team, a server-side API key, approved models and data retention, rate and spend budgets, representative evaluations, tool authorization, content and media controls, observability, and incident ownership.
- 04
Sign in with the account you intend to keep using, then review plan, data, notification, and permission settings.
- 05
Run one low-risk test task before connecting sensitive files, repositories, or workspace data.
- Use official download pages.
- Review permissions during setup.
- Keep installers and applications updated.
First session
Your first useful xAI API session
Learn the interaction loop using a small task with a clear outcome.
- 01
Define the user task, modalities, data classes, quality and safety metrics, latency, tools, storage, retention, cost, approval, and rollback requirements.
- 02
Create a dedicated team key, keep it server-side, choose a current model from the authenticated models endpoint, and decide whether default retention, store=false, or team-wide Zero Data Retention fits the workload.
- 03
Build a frozen evaluation set and make a bounded Responses API request with explicit instructions, output schema, tools, token and request limits, timeouts, retries, and redacted request telemetry.
- 04
Test quality, safety, privacy, tool authorization, latency, rate limits, media lifecycle, and total task cost, then canary with quotas, human approval for consequential actions, and a tested fallback.
- State the outcome before the background.
- Provide the real source material.
- Review the result before expanding the task.
Quality control
Check the quality of xAI API output
Turn generated code into a change you would put your name on in review.
- 01
Restate the intended behaviour and the acceptance criteria before reading a single generated line.
- 02
Read the diff rather than the chat summary; the summary describes intent, the diff describes what actually changed.
- 03
Run the test suite, then write a test that would fail if the change were wrong, and confirm it passes for the right reason.
- 04
Check the edges the model tends to skip: error paths, null and empty cases, concurrency, and migration or rollback behaviour.
- 05
Trace every new dependency, network call, and file write, and confirm each one is genuinely required.
- Review the diff, never the description of the diff.
- A passing test suite proves the tests pass, not that the change is correct.
- Keep changes small enough that a human can actually review them.
Privacy & permissions
Use xAI API safely
Give the tool enough repository access to help, and no more than that.
- 01
Decide what the tool may read and what it may write before connecting a repository.
- 02
Scope tokens and integrations to the narrowest repository, branch, and permission set that still works.
- 03
Keep secrets out of the context window: use environment variables and secret stores, never inline credentials.
- 04
Require review before generated code touches authentication, payments, permissions, migrations, or deletion paths.
- 05
Audit what the integration retained after the session, and revoke access that is no longer needed.
- By default, xAI says API requests and responses are encrypted at rest and retained for 30 days for abuse auditing, though not used for training without explicit permission. Team-wide Zero Data Retention prevents prompt and output persistence but disables or changes stored Responses, Files, Collections, Batch, deferred, media, and voice-history features. Keep keys server-side, verify the response retention header, minimize data, set storage deliberately, authorize tools outside the model, expire or delete files and public URLs, and never expose model-selected actions directly.
- Follow your organisation's approved-use policy.
- Never treat fluent output as authorization to act.
Core workflows
Step-by-step ways to use xAI API for the work it does best.
Each workflow is a separate guide with its own steps and review checkpoints.
Treat Grok-selected tools and arguments as untrusted proposals while identity, authorization, validation, execution, and approval stay in application code.
↗ 02 WorkflowOperate xAI files and generated media safelyControl upload, generation, sharing, expiration, download, moderation, rights review, and deletion as one explicit asset lifecycle.
↗Official references
Check the current product documentation.
Features, plan limits, availability, and data controls change. These official pages are the starting points used for this guide.