# Grok API: pricing, API key and first steps for developers

> Grok API in November 2026: pricing by model, the 200k-token threshold, OpenAI SDK, data retention, Zero Data Retention and the AI Act watermark.

Source: Giallo Studio (giallostudio.it) · Page: https://giallostudio.it/en/blog/grok-api-guide · Published: 2026-11-08 · Updated: 2026-11-08

**You use the Grok API with the OpenAI SDK by pointing it to https://api.x.ai/v1, and as of November 2026 the flagship model, Grok 4.7, costs $2 per million input tokens and $6 per million output tokens, as long as the prompt stays under 200,000 tokens.** Above that threshold the entire request moves to $4 and $12 ([official pricing](https://docs.x.ai/developers/models), read on November 8, 2026). You create the key in the developer console; requests and responses are retained for 30 days for abuse monitoring.

The documentation is now called “SpaceXSI API Documentation”: SpaceXSI is the new name of the company known as xAI, but the API stays on api.x.ai ([docs.x.ai](https://docs.x.ai/llms.txt)). This guide is for anyone deciding whether and how to integrate Grok: pricing, first steps, data choices and the October and November 2026 changes that affect production work.

<div class="key-points">
<p class="kp-title">In summary</p>
<ul>
<li>Grok 4.7: 500,000-token context window, text and image input, text output, reasoning from low to xhigh.</li>
<li>Threshold pricing: under 200k prompt tokens, $2 / $6; from 200k up, $4 / $12 on the entire request.</li>
<li>Compatible with the OpenAI SDK, with Responses API, function calling, web and X search, Batch API and remote MCP.</li>
<li>API data retained for 30 days; Zero Data Retention is available, but with fewer features. No documented EU endpoint.</li>
<li>Since November 7, 2026, text responses carry an invisible watermark, on by default.</li>
</ul>
</div>

## How much does the Grok API cost per model?

Prices are per million tokens, in dollars, as published on the [models page](https://docs.x.ai/developers/models) on November 8, 2026. If per-token pricing is new to you, start with [price per million tokens explained](https://giallostudio.it/en/blog/price-per-million-tokens-explained).

| Model | Context window | Input | Cached input | Output |
| --- | --- | --- | --- | --- |
| **grok-4.7**, prompt under 200k | 500k | 2 $ | 0,50 $ | 6 $ |
| **grok-4.7**, prompt 200k and up | 500k | 4 $ | 1 $ | 12 $ |
| grok-4.6, grok-4.5 | 500k | 2 $ | — | 6 $ |
| grok-4.3, grok-4.20 | 1M | 1,25 $ | — | 2,50 $ |
| grok-build-0.1 | 256k | 1 $ | — | 2 $ |

Empty cells mark items we haven't listed because they were not in our reading. Grok 4.7, announced on September 21, 2026 “at the same price and speed as Grok 4.6” ([announcement](https://x.ai/news/grok-4-7)), has a May 2026 knowledge cutoff ([model card](https://docs.x.ai/developers/grok-4-7)).

Voice and images have separate rates: grok-voice-3.0 speech-to-speech $0.08 per minute, speech-to-text $0.10 per hour, text-to-speech $15 per million characters; images from $0.02 (grok-imagine-image) or $0.04 (grok-imagine-image-2.0) each, video from $0.020 to $0.080 per second depending on the model.

## How does the 200,000-token threshold work?

It's the line item that surprises people most in quotes. For Grok 4.7 the higher rate doesn't apply only to the tokens above the threshold: if the prompt reaches 200,000 tokens, it applies to every token in the request. An example with our own numbers:

| Request | Calculation | Cost |
| --- | --- | --- |
| 150,000 input tokens, 4,000 output tokens | 0,15 × 2 + 0,004 × 6 | **0,324 $** |
| 250,000 input tokens, 4,000 output tokens | 0,25 × 4 + 0,004 × 12 | **1,048 $** |

With 67% more input, the request costs more than three times as much. For an agent that rereads an archive at every step, keeping the context under the threshold (by summarizing, by retrieving only the relevant documents) is one of the strongest cost levers. The general method for estimating spend is in [AI API costs: how to calculate them](https://giallostudio.it/en/blog/how-to-calculate-ai-api-costs).

One last note on pricing: Grok 4.7 Fast, the same model on faster infrastructure, costs twice as much (1.5 times on long context) and is available only in Cursor and Grok Build, not on the public API ([Grok 4.7 model card](https://docs.x.ai/developers/grok-4-7)).

## How do you make your first Grok API call?

The API is compatible with the OpenAI SDK: you only need to change the base URL and the key ([documentation](https://docs.x.ai/developers/grok-4-7)). A minimal sequence:

<ol class="steps">
<li><strong>Create the key in the developer console.</strong> Treat it like a password: a secrets manager or an environment variable, never in the repository or in a browser-side app.</li>
<li><strong>Configure the client.</strong> OpenAI SDK with <code>base_url</code> set to https://api.x.ai/v1 and your API key.</li>
<li><strong>Pick the model.</strong> <code>grok-4.7</code> for complex tasks; cheaper models for classification and repetitive work.</li>
<li><strong>Set spending caps and logging.</strong> Before you open the service to users, not after the first invoice.</li>
</ol>

A Python example with the Responses API:

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XAI_API_KEY"],  # nome della variabile a tua scelta
    base_url="https://api.x.ai/v1",
)

risposta = client.responses.create(
    model="grok-4.7",
    input="Riassumi in tre punti le condizioni di consegna di questo testo: ...",
)
print(risposta.output_text)
```

Besides the Responses API, the documentation lists function calling, web search, X search, code execution, Batch API, prompt caching and remote MCP ([official index](https://docs.x.ai/llms.txt)). Grok 4.7 is also available through OpenRouter, Vercel and Cloudflare, and the documentation mentions Google Cloud Vertex AI and Microsoft Foundry. If you're just starting out, the big picture is in [what AI APIs are](https://giallostudio.it/en/blog/what-are-ai-apis).

## Do you need web search to get up-to-date information?

Yes. Through the API, without the Web Search or X Search tools turned on, Grok knows nothing about events after its training data ([models page](https://docs.x.ai/developers/models)). Anyone searching for “grok bot x api” in the hope of direct access to the X feed has to go through X Search, an API tool that you need to turn on and budget for.

The @bot tag on X, on the other hand, is not an API: it passes a post to your own Grok Bot, the agent described in [What is Grok Bot](https://giallostudio.it/en/blog/what-is-grok-bot), and it is not available for EU-based accounts.

## What happens to data sent to the Grok API?

The [security FAQ](https://docs.x.ai/developers/faq/security) is the document to read before sending any customer data. The main points:

- **Training.** SpaceXSI states that it does not train its models on API inputs and outputs without explicit permission.
- **Retention.** Requests and responses are kept for 30 days, encrypted, for abuse monitoring, then deleted.
- **Zero Data Retention.** It is enabled at team level, but it turns off everything that requires storage: stateful Responses API, Files, Collections, Batch API, deferred completions. The documentation itself advises most customers against it.
- **Certifications.** Asked about GDPR and SOC 2, the FAQ answers that it is SOC 2 Type 2 compliant and points to the Trust Center, accessible under NDA.
- **End users.** The `safety_identifier` field takes an opaque user identifier, to be hashed (never an email or phone number), so violations are attributed to the individual user rather than to the whole API key.

On regions, the [dedicated page](https://docs.x.ai/developers/advanced-api-usage/regions) says api.x.ai does not guarantee where processing takes place. There is a US endpoint, us.api.x.ai, priced 10% higher, which serves only grok-4.7 and grok-4.6. No EU endpoint is listed. For a European business, this means a non-EU transfer to assess with a DPA and a risk analysis.

<div class="callout"><strong>Before going to production</strong> Use <code>safety_identifier</code> with a hash of the user ID: if a single user abuses the service, the block falls on that user and not on the key that runs your whole application.</div>

## What changed between October and November 2026?

Three changes that affect anyone who already has an integration:

| Date | Change | Impact |
| --- | --- | --- |
| October 2026 | Custom moderation controls (`guidelines` for nsfw, violence, profanity) on text requests | Filters can be adapted to the application's context |
| November 2, 2026 | grok-imagine-image-quality retired: requests move to grok-imagine-image-2.0 at low quality | Check the quality and cost of generated images |
| November 7, 2026 | Invisible text watermark in responses from grok-4.7, 4.6, 4.5, 4.3 and 4.20, for EU AI Act compliance | On by default; admins can turn it off per model; header `x-watermark` |

Sources: [release notes](https://docs.x.ai/developers/release-notes) and [watermarking page](https://docs.x.ai/developers/advanced-api-usage/watermarking), read on November 8, 2026. For European users, the API console made Grok 4.5 available in July 2026.

## What does it cost per month, and how do you keep it under control?

A hypothesis of ours to show the method: an internal assistant that answers 500 questions a day over 22 working days, with 8,000 input tokens and 800 output tokens per question. That's 88 million input tokens and 8.8 million output tokens a month. With grok-4.7 under the threshold and no cache: 88 × 2 + 8.8 × 6 = 176 + 52.80 = **$228.80 a month**. If half the input were recognized as cached ($0.50), the input line would drop from $176 to $110.

The levers that keep it stable: stay under 200,000 tokens, use the cache for repeated instructions and documents, use cheaper models for simple tasks. It's the approach we describe in [mixed-model strategy](https://giallostudio.it/en/blog/mixed-ai-model-strategy). A cash-flow detail: API credits are non-refundable ([FAQ](https://docs.x.ai/grok/faq)), so it's best to top up in small amounts.

## What mistakes should you avoid in your first integration?

The ones we see most often in projects with any vendor, applied to Grok:

- **Key in the frontend.** An API key exposed in the browser is a public key: calls should always go through a server.
- **Forgetting the threshold.** A prompt that grows by a few documents can exceed 200,000 tokens and change the rate for the whole request.
- **Counting on current events without tools.** Without Web Search or X Search the model stops at its May 2026 cutoff.
- **Turning on Zero Data Retention mid-project.** It switches off Files, Batch API and stateful Responses API: decide before you design the architecture.
- **Ignoring the watermark.** Since November 7, 2026 it is on by default: anyone who processes or compares generated text needs to know.

## When should you integrate Grok into a business system?

Grok makes sense through the API when you need X search, low prices under the threshold or a 500,000-token context. On its own it is rarely enough: in most projects you want an architecture where the model is a replaceable part, with a layer that manages keys, logs, spending limits and data rules. How to connect a model to management software and a CRM is covered in [integrating AI into existing systems](https://giallostudio.it/en/blog/integrate-ai-existing-systems); when the goal is to remove manual steps from an entire workflow, the place to start is [business process automation](https://giallostudio.it/en/business-process-automation).

That middle layer is the part we build: separate keys per environment, a budget per key, searchable logs and the option to switch from Grok to Codex, Gemini or Claude without rewriting the integration. These are the [AI agents](https://giallostudio.it/en/ai-agents) by Giallo Studio. If you have an integration in mind, [tell us about the project](https://giallostudio.it/en/contact).

## Frequently asked questions

### How much does the Grok API cost?

As of November 2026, Grok 4.7 costs $2 per million input tokens, $0.50 cached and $6 output while the prompt stays under 200,000 tokens; from 200,000 up it costs $4, $1 and $12 on every token in the request. Grok 4.3 and Grok 4.20 cost $1.25 and $2.50, grok-build-0.1 $1 and $2. Source: docs.x.ai, read on November 8, 2026.

### How do you get a Grok API key?

You create the key in the developer console of SpaceXSI, the company that develops Grok, and use it with the endpoint https://api.x.ai/v1. Store it as a secret, in an environment variable or a secrets manager, never in your code or frontend.

### Is the Grok API compatible with the OpenAI SDK?

Yes. According to the official documentation, the API works with the OpenAI SDK when you set the base URL https://api.x.ai/v1, and it supports Responses API, function calling, web and X search, code execution, Batch API, prompt caching and remote MCP.

### Is there a free Grok API plan?

We found no confirmation on any official page read on November 8, 2026, so we don't assume one exists. The Plus plan of The X Subscription, at $8 a month, lists Grok API access, and the plans' weekly allowance also covers the API. API credits are non-refundable.

### Does SpaceXSI use data sent through the API to train its models?

No, according to the security documentation, unless you give explicit permission. Requests and responses are, however, retained for 30 days, encrypted, for abuse monitoring, and then deleted. If you need nothing retained, you can turn on Zero Data Retention at team level and give up some features.

### Is there a European endpoint for the Grok API?

No, not in the documentation read on November 8, 2026. The main endpoint, api.x.ai, does not guarantee the processing region; there is a US endpoint, us.api.x.ai, priced 10% higher, which serves only grok-4.7 and grok-4.6.
