You open the xAI docs to plan a content-generation budget and immediately run into two different metrics. One section bills by tokens, another by the piece. Mix up the endpoints or send a text prompt to a visual model, and your logs fill up with errors while the infrastructure bill blows past the forecast.
Input and output tokens in text models
Let's start with text. Grok language models are billed by the volume of data they process. The base unit is a token: the smallest chunk of text the model reads in one computation step. Usually that's part of a word, or a single character in code.
The provider splits the price list into two strict categories. The first is input tokens: your prompt, system instructions and the context you pass to the model. The second is output tokens, the answer the model generates.
The core rule of Grok API economics: writing always costs more than reading. As of August 28, 2026, output tokens cost exactly three times as much as input tokens on every text model. That price gap directly shapes your application's architecture.
Load inversion: how the direction of text changes the bill
Look at the edge cases of the context-to-answer ratio. If you send a huge database dump and ask for a short JSON with conclusions, you pay little. The compute goes into reading, and reading is billed at the base rate.
If you give a short command to write a long analytical report, the meter runs on expensive output tokens. Picture a load inversion on the same volume of data. Say the task's total budget is 1,200 tokens.
In the first scenario you send 800 input tokens and get 400 back. In the second you send a 400-token prompt and the model generates an 800-token answer. The total amount of processed text hasn't changed.
But because generation costs three times as much as reading, the second scenario costs you considerably more. Your project's math only works if you strictly cap the maximum answer length on the client side.
Visual generation and the metric clash
Media models work differently. The lineup includes the grok-imagine, grok-imagine-2 and grok-imagine-video endpoints. The token concept doesn't apply here at all.
You pay for each successful generation of one image or one video clip. These are fundamentally different billing units, and you can't apply token logic to the cost of visual content.
Send a long text prompt to a visual model while expecting to be charged fractions of a cent per token, and you've punched a hole in your budget. It will run dry after the first few dozen calls. Visual endpoints need a separate billing loop in your application, one that isn't tied to tokens.
Gateway access and the identical-pricing anomaly
Connecting to xAI directly stalls at the step where you add a corporate card. The direct route requires foreign payment gateways or a foreign legal entity. Intermediary payment services often charge unpredictable fees. We don't recommend non-standard traffic-routing workarounds for a commercial product: they break fault tolerance.
We solve this at the API gateway level. The altrouter platform gives you access to the models with payment in rubles. As of August 28, 2026, the rates include a 15% discount off the vendor's official price. You send a request to our address, and we forward it to the provider.
The versions have a non-obvious quirk. grok-4.6 and grok-4.5 cost exactly the same. The intuitive "higher version number, pricier call" rule breaks down here.
We haven't run benchmarks or compared text-generation quality between these two versions. You'll have to choose by running your own prompts through both. There's no price difference between the two endpoints, so blindly moving to the newer version without testing makes no sense.
Cost on a pool of 10,000 tasks
We ran a synthetic test to estimate the budget. We took an array of 10,000 similar requests with a fixed context size. Each request uses 800 input tokens and 400 output tokens.
Total consumption for the whole pool came to 8 million input and 4 million output tokens. Where do these numbers come from? 800 prompt tokens × 10,000 tasks gives 8 million input. 400 answer tokens × 10,000 tasks gives 4 million output.
All prices below are fixed as of August 28, 2026 and already include our 15% discount off the vendor's official price. We didn't align temperature or system prompts: only the answer length affects the final bill.
| Model | Our input (per 1M) | Our output (per 1M) | Official (input/output) | Pool cost |
|---|---|---|---|---|
| grok-4.6 | $1.70 | $5.10 | $2 / $6 | $34.00 |
| grok-4.5 | $1.70 | $5.10 | $2 / $6 | $34.00 |
| grok-4.3 | $1.0625 | $2.125 | $1.25 / $2.5 | $17.00 |
This run makes xAI's math obvious. Because generation costs three times as much as reading ($5.10 vs $1.70 on grok-4.6), the answer length is what drives the bill. grok-4.3 comes out roughly half the price on output tokens.
For grok-4.3 the math looks different. Eight million input tokens at $1.0625 cost $8.50. Four million output tokens at $2.125 add another $8.50. The total is exactly $17.00.
So the whole task pool cost us $17.00 on grok-4.3, versus $34.00 on the senior versions. Your choice of model directly sets the margin of your feature.
Go back to the load-inversion thought experiment and the results change. Run the math for grok-4.6: four million input tokens at $1.70 give $6.80. Eight million output tokens at $5.10 give $40.80. The total bill climbs to $47.60.
The $13.60 difference comes purely from changing the ratio of context to answer. The total of 12 million tokens stays the same.
Integration via the OpenAI SDK
Grok endpoints are fully compatible with the OpenAI standard. You don't have to rewrite your networking logic or change your response parsers. Generate a key in the dashboard.
Change base_url (the address the library sends requests to) to ours. Pass the key the standard way. Leave the rest of the code alone.
import openai client = openai.OpenAI( api_key="YOUR_KEY", base_url="https://api.altrouter.ai/v1" ) response = client.chat.completions.create( model="grok-4.3", messages=[ {"role": "user", "content": "Generate a metrics report"} ] ) print(response.choices[0].message.content)
This script copies as-is and runs in any environment with the OpenAI package installed. The answer comes back in the familiar format. The messages array keeps its structure, so you pass system instructions and conversation context exactly as you did before.
Dependency on upstream servers
The gateway solves billing, but it doesn't remove architectural risk. Our downside is plain: we act purely as a router. If xAI's servers go down under load or into maintenance, the models disappear on our side too.
We relay your requests to the original API. There's no magic layer that generates an answer when the vendor is down. You need to build retry logic into your application; the guide to error 429 shows how to retry properly.
If the original provider returns a timeout error, altrouter passes that status on to your client. Handling these failures is entirely up to your code, and the status codes are listed in the errors reference.
Count tokens before you ship code to production. Test the junior versions on routine tasks: they often do just as well and cut the budget in half. Sign up and get API keys at altrouter.ai; current prices are in the model catalog.
FAQ
How much does Grok image generation cost?
The grok-imagine, grok-imagine-2 and grok-imagine-video models are billed per successful generation. Text token metrics don't apply to them. As of August 28, 2026, the exact price of a single image generation wasn't broken out line by line in our logs.
Why do grok-4.6 and grok-4.5 cost the same?
What is the cheapest Grok model?
Among text models, as of August 28, 2026, the cheapest is grok-4.3. It costs $1.0625 input and $2.125 output per million tokens, with a 15% discount off the vendor's official price. On generation cost it's half the price of the senior versions.
How do I set up a Grok API key?
You don't need an original xAI key. You get a key on the router platform and change the base_url parameter in your OpenAI-compatible client, as described in the authentication docs. The rest of your application's business logic stays the same.