GLM 5 Context Window: What This API Gives You
People searching for the glm 5 context window usually want a number they can plan around. On this API the number is 100,000 tokens, shared between your prompt and the model's reply.
Updated
Key points
- The window is 100,000 tokens in total: prompt plus completion.
- max_tokens is optional; the completion may use whatever the prompt leaves free.
- A full 100,000-token prompt costs $0.015 in input; a 100,000-token reply costs $0.05.
- Chat history is resent on every turn, so long sessions need trimming or summaries.

The number and what it covers
This service has a context window of 100,000 tokens. That budget is shared: everything you send (system prompt, chat history, documents, tool definitions) and everything the model writes back must fit inside it together. If your prompt is 70,000 tokens, the reply can use up to 30,000.
One caveat: this API serves a single open-weight model run by an independent provider. It is not the official API of any model vendor, and this page cannot state the limits of another provider's hosted models. If you need the window of a specific model on a specific platform, read that platform's documentation. What follows is about this endpoint, https://api.glmapi.top/v1, with the model ID uncensored.
How much text is 100,000 tokens
A token is a chunk of text, not a word. For ordinary English prose a rough rule is that one token is about three quarters of a word, so 100,000 tokens is on the order of 75,000 words. Treat that as an estimate. Code, tables, URLs and non-English text split into more tokens per word, so the same window holds less of them.
| Content | Rough token count |
|---|---|
| A short chat message | 20 to 100 |
| A one-page email | 400 to 700 |
| A 10-page report | 5,000 to 7,000 |
| A 200-page book | 70,000 to 90,000 |
These figures are approximations from general experience with English text, not measurements of this model. The only exact count comes from the usage field that the API returns with each response, so measure your own content once and use that.
If you are unsure whether your input fits, estimate before sending: divide the character count by four for English text, which gives a token count that is usually close enough to decide between sending and splitting. Always keep a margin of a few thousand tokens for the reply and for formatting overhead such as role markers and tool definitions.
The window is also the ceiling for fiction and roleplay sessions. A long character conversation with a detailed persona prompt can approach it after many turns, which is why the trimming advice below matters for companion and story apps.
Prompt plus completion: how the budget splits
Because the window is shared, there are two ways to hit the wall: a prompt that is too large, or a prompt that leaves too little room for the answer.
The max_tokens parameter is optional. If you leave it out, the completion can use whatever space remains. If you set it, set it to what you actually need. A summary that should be 300 tokens does not need a limit of 8,000, and a lower value protects you from a runaway reply that costs more than expected.
A simple planning formula:
free_for_reply = 100000 - prompt_tokens
expected_reply <= free_for_reply
If a request is over the limit, the right fix is almost always to send less, not to ask for less output. Remove stale history, shorten documents to the relevant parts, or split the job into stages.
What a long prompt costs
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, prepaid, with failed or refused requests not charged. Large contexts are cheaper than most people expect. Here are exact examples.
- Full window as input. 100,000 × $0.15 / 1,000,000 = $0.015.
- Full window as output. 100,000 × $0.50 / 1,000,000 = $0.05.
- Long document question. 90,000 tokens in and 10,000 out: 90,000 × $0.15 / 1,000,000 = $0.0135, plus 10,000 × $0.50 / 1,000,000 = $0.005, for $0.0185 in total.
- A 50-turn chat. See below.
The chat case is where the bill grows without anyone noticing. A chat API does not remember anything: every request carries the entire history. Suppose the history plus the new message is 1,000 tokens on turn 1, 2,000 on turn 2, and so on up to 50,000 on turn 50, and each reply is 700 tokens. Total input is 1,000 × (1 + 2 + ... + 50) = 1,000 × 1,275 = 1,275,000 tokens, which costs 1,275,000 × $0.15 / 1,000,000 = $0.19125. Output is 50 × 700 = 35,000 tokens, costing $0.0175. The session comes to about $0.21. Cheap, but notice that input grows with the square of the number of turns, so a session ten times longer would cost far more than ten times as much. See the pricing page for top-up amounts and bonuses.
Measuring your usage in code
Do not guess. Read the token counts from the response and log them.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.glmapi.top/v1",
api_key=os.environ["GLM_KEY"],
)
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarize the plot of Hamlet."}],
)
u = resp.usage
cost = u.prompt_tokens * 0.15 / 1e6 + u.completion_tokens * 0.50 / 1e6
print(u.prompt_tokens, u.completion_tokens, round(cost, 6))
print(100000 - u.prompt_tokens - u.completion_tokens, "tokens left in window")
Streaming responses include usage at the end of the stream, so the same bookkeeping works there. Each response also carries X-Balance-USD, which shows the balance after the call, and X-Request-Id, which you should keep for support questions.
Keeping a long conversation inside the window
Three techniques cover nearly every case. They can be combined.
Sliding window
Keep the system prompt and the most recent N messages, and drop the rest. It is simple and predictable. Its weakness is that facts from early in the conversation disappear completely.
Rolling summary
When the history passes a threshold, say 60,000 tokens, ask the model to summarize the oldest half into a few hundred tokens and replace those messages with the summary. This keeps the important facts, such as character details in a story or user preferences in an assistant, at a small token cost.
Retrieval
For large document sets, do not paste everything. Store chunks outside the prompt and insert only the passages relevant to the current question. This API has no embeddings endpoint, so the vector search has to come from another tool.
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.glmapi.top/v1", api_key=os.environ["GLM_KEY"])
def trim(messages, used_tokens, budget=60000):
# Drop the oldest non-system messages until under budget.
system, rest = messages[:1], messages[1:]
while used_tokens > budget and len(rest) > 2:
rest.pop(0)
used_tokens -= 500 # replace with real counts from usage
return system + rest
The placeholder subtraction in that helper is a stand-in; in a real app, store the token count of each message when you first see it. The point is to enforce the budget before sending, not after the error.
Does a bigger window mean better answers
Not automatically. A model can accept 100,000 tokens and still handle the middle of a very long prompt less reliably than the beginning and the end. There is no benchmark here to quote, so test with your own material: ask questions whose answers sit at the start, middle and end of a long input, and see whether all three come back correct.
If the answers degrade, put the instructions and the question at the end of the prompt, repeat the key constraint once, or split the document and process it in stages. Smaller prompts are also cheaper and give the model fewer chances to lose track of a detail, so use the window when the task needs it, not by default. The request format, streaming and other parameters are described in the API docs, and you can compare this service with another option on the Hermes comparison page.
More guides
Questions and answers
What is the context window of this API?
It is 100,000 tokens in total, counting the prompt and the completion together.
Do I have to set max_tokens?
No, it is optional. Without it the completion can use the space the prompt leaves free. Set it when you want to cap reply length and cost.
Is this the official GLM 5 API?
No. It is a single open-weight model run by an independent provider and is not the official API of any vendor. For another platform's limits, read that platform's documentation.
What happens if my prompt is too long?
The request cannot fit in the window, so you must shorten it. Trim history, summarize older turns, or send only the relevant parts of a document.
What is the maximum request size?
The body can be up to 8 MB. The token window of 100,000 is usually the tighter limit.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.
Get API key