EN ▾
Get API key

Grok 4 Context Window and a 100k Alternative

The grok 4 context window is set by xAI, so confirm the current number in their model documentation. This article covers what a window actually limits and how to work inside the 100,000 tokens our API gives you.

Updated

Scroll of glass panels filling with glowing beads to show a 100,000-token context window

Key points

  • Our context window is 100,000 tokens, shared between your prompt and the completion.
  • For Grok's size, read xAI's current model docs, since vendors change these figures.
  • System prompt, chat history, tool definitions and tool results all count toward the window.
  • A rolling summary plus recent turns keeps long roleplay inside the window and cuts cost.

Short answer and where to check Grok

If you need the exact grok 4 context window, look at xAI's own documentation, because the figure belongs to them and may be updated. I will not quote a number I cannot verify. This service is not xAI's API and does not run Grok. It serves one open-weight model, run by an independent provider, with model ID uncensored.

The facts for this API are simple. The context window is 100,000 tokens, and that budget covers the prompt and the completion together. There is no separate output cap: the reply can use whatever the prompt leaves free, and max_tokens is optional. The request body is limited to 8 MB, which you will not reach with text before you hit the token limit.

The rest of this page is about living with a window of that size: what counts against it, how to measure it, and how to trim without losing the thread of a story or a document.

What counts against the window

People often think of the window as the size of the document they paste in. It is bigger than that. Everything you send in messages counts, plus whatever the model writes back.

  • The system prompt, on every request.
  • Every earlier user and assistant message you resend.
  • Tool definitions in the tools array, and tool results you append as role: "tool" messages.
  • The completion itself, including a streamed one.

Since chat APIs are stateless, the history is yours to manage. If you send the full conversation every turn, the prompt grows by the size of each exchange until it fills the window. A long roleplay with detailed character sheets can get there faster than you expect, which is why the strategies below matter more than the raw number.

How much text fits in 100,000 tokens

A token is a piece of a word. For ordinary English prose, a common rule of thumb is about three quarters of a word per token, so 100,000 tokens is roughly 75,000 words. That is the length of a short novel, minus the room you need for the reply. Code, other languages, tables and unusual names split into more tokens per word, so the same window holds less.

Treat the ratio as an estimate and measure when it matters. The response from every request includes a usage block with prompt and completion token counts, and with streaming the usage arrives at the end. A quick way to calibrate is to send a representative prompt with a small max_tokens, read the prompt count, and compute your own words-per-token figure for your kind of content.

ContentRough fit in the window
English prosearound 75,000 words including the reply
Chat history of 500-token exchangesa few hundred exchanges, minus the system prompt
Source codenoticeably fewer lines than prose estimates suggest, so measure

Budgeting the window for a long roleplay

Give each part of the request a budget instead of letting history eat everything. One workable split for a story or companion chat:

  • System prompt and character sheet: 2,000 tokens, pinned.
  • Long-term memory (a running summary): 3,000 tokens.
  • Recent turns, verbatim: up to 80,000 tokens.
  • Room for the reply: 15,000 tokens, far more than you will use.

That adds up to 100,000. In practice you will set the recent-turns budget lower, because a model keeps better track of details when the prompt is short, and because every token in the prompt is billed on every turn. Models can also lose details buried in the middle of a very long prompt, so test your own setup instead of assuming the full window gives full recall.

When recent turns pass their budget, summarise the oldest block with a separate call and append the result to the memory section. The summary call costs a little, but it reduces every later request.

Code: trim history to fit

This helper keeps the system message, drops the oldest turns until the estimate fits a budget, and sends the request. It estimates tokens as characters divided by four, which is rough but safe for English when you leave a margin. For exact numbers, use a tokenizer or the usage block.

from openai import OpenAI

client = OpenAI(base_url="https://api.groknsfw.cc/v1", api_key="YOUR_KEY")

def est_tokens(msg):
    return len(msg["content"]) // 4 + 4

def trim(messages, budget=60_000):
    system, rest = messages[0], messages[1:]
    used = est_tokens(system)
    kept = []
    for msg in reversed(rest):          # newest first
        cost = est_tokens(msg)
        if used + cost > budget:
            break
        kept.append(msg)
        used += cost
    return [system] + list(reversed(kept))

history = [{"role": "system", "content": "You are the narrator of a slow-burn mystery."}]
history.append({"role": "user", "content": "Continue the scene at the lighthouse."})

reply = client.chat.completions.create(
    model="uncensored",
    messages=trim(history),
    max_tokens=1200,
)
print(reply.choices[0].message.content)
print(reply.usage.prompt_tokens, reply.usage.completion_tokens)

Set the budget well under 100,000 so the completion has room. A budget of 60,000 leaves 40,000 tokens of space for the answer, which is generous. If you want the model to remember something that would be dropped, put it in the pinned system prompt or in the summary block instead of relying on old turns.

Long documents: ask once or in pieces

If a document plus your question fits in the window, send it whole. You get an answer that sees all the text at once, which helps with questions about relationships across sections. Cost is small at our rates: a call with 90,000 input tokens and 2,000 output tokens costs 90,000 x 0.15 / 1,000,000 = $0.0135 plus 2,000 x 0.50 / 1,000,000 = $0.001, which is $0.0145.

The trap is repetition. If you ask ten questions about the same document and resend it each time, you pay for the document ten times: 10 x $0.0145 = $0.145. That is still cheap for one document but adds up over a library. Ask several questions in one prompt when you can, and request a structured answer with JSON mode (response_format: {"type":"json_object"}) so you can split the replies in code.

If the document is longer than the window, split it into chunks that each fit, extract notes from every chunk, then run a final call over the notes. Keep the chunks around 20,000 to 40,000 tokens so the model attends well and the calls stay fast to stream.

When a bigger window is not the answer

It is tempting to look for the largest window you can find and paste everything in. That works for a one-off question. For anything that runs every day, it has costs. Every token in the prompt is billed again on each request, a long prompt takes longer to process, and the model has more text to sift for the detail you care about.

Retrieval is a good alternative for knowledge that is bigger than the window or that you reuse often. Split your material into passages, store them in your own database, find the few that match the user's question, and send only those. This service does not offer embeddings, so you would use a separate tool for the search step, then send the chosen passages to the chat endpoint. For a story, the equivalent is a short list of facts about the characters and plot, pulled in when relevant, instead of the entire transcript.

A practical rule: if the same large block goes into every request, ask whether it can be shortened. A 10,000-token character bible that could be a 1,500-token summary saves 8,500 input tokens per turn. Over 1,000 turns that is 8.5M tokens, or $1.275 at $0.15 per 1M.

Practical tips and limits to remember

A few details save debugging time. Do not fill the window to the last token; leave a margin for the reply and for tokenizer differences from your estimate. Large prompts send more bytes, but 8 MB is far above what 100,000 tokens of text needs. Long requests run longer, and a streamed request holds its concurrency slot until the stream ends, so a full key's 8 concurrent slots can fill up when several big prompts run at once.

Good starting points are the quickstart for the request format, the pricing page for cost planning, and the Grok API guide if you are weighing this service against xAI. To try a long prompt without paying first, claim the $0.50 trial credit on the API key page.

Questions and answers

How big is Grok's context window?

That is defined by xAI and may change, so check their current model documentation. Our API gives you 100,000 tokens for prompt plus completion.

Does the 100,000-token limit include the reply?

Yes. The prompt and the completion share the window, and the completion can use whatever the prompt leaves free.

Does the trial key have different limits?

The trial key allows 2 concurrent requests and 60 requests per minute, against 8 and 300 on a full key. The context window of 100,000 tokens is the figure for the service.

How do I know how many tokens I used?

Read the usage block in the response, which reports prompt and completion tokens. In streaming mode the usage arrives at the end of the stream.

How much does a very long prompt cost?

A prompt of 90,000 tokens with a 2,000-token reply costs $0.0145 at $0.15 per 1M input and $0.50 per 1M output tokens.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key