EN ▾
Get API key

LLM Context Window Limit: Working Within 100k Tokens

The llm context window limit on this API is 100,000 tokens, counting your prompt and the model's reply together. That is roughly 75,000 English words, or a few hundred chat turns, and this article shows how to measure it and trim history in code before you reach it.

Updated

  • 100,000 tokens cover the whole request: system prompt, history, new message and completion.
  • Roughly 75,000 English words, or about 150 pages at 500 words a page.
  • Resending a full window every turn costs about $0.015 of input per request.
  • Trim by dropping or summarizing the oldest turns, and always keep the system prompt.
A glass gauge holding a scroll of text strips with older ones condensing into a gold sphere, showing a context window

Key points

What 100,000 tokens means in practice

A context window is the amount of text a model can consider in one call. It is shared: everything you send plus everything the model writes must fit inside it. With a 100,000 token window, a prompt of 95,000 tokens leaves room for only 5,000 tokens of reply.

Tokens are not words. For English prose, one token is about four characters, or three quarters of a word. Other languages and code often need more tokens per word. Using the English rule of thumb:

ContentApproximate tokens
A short chat message (20 words)about 27
A typical chat turn pair, user and reply150 to 400
One page of text (500 words)about 670
A 10,000 word short storyabout 13,300
The whole 100,000 token windowabout 75,000 words, 150 pages

If a chat exchange averages 300 tokens, the window holds around 330 of them. A roleplay or companion chat can pass that in a few evenings, so planning for the limit is not theoretical.

What happens when you go over

The window does not stretch. Plan for a prompt plus reply that exceeds 100,000 tokens to be rejected as an error, and write your code so it catches that case instead of assuming the text will be cut for you. Failed requests are not charged, but you still need to handle the failure; the docs list the exact error responses. The request body is also capped at 8 MB, which in practice is never the limit that bites first.

max_tokens is optional. If you leave it out, the completion may use whatever is left of the window. If you set it, the prompt must still fit with that much room to spare. A frequent bug is setting max_tokens to a large number out of habit and then wondering why a long prompt fails.

Models can also pay less attention to material in the middle of a very long prompt. Quality at 90,000 tokens is not the same as quality at 9,000. Having a big window does not mean you should fill it.

A practical habit is to decide a working budget for each kind of request. A quick question may need only 2,000 tokens of context. A long story session may justify 40,000. A document summary might use 80,000 once. Writing these budgets down, per feature, makes the cost and the failure modes predictable, and keeps one chatty feature from eating the window that another one needs.

Count tokens before you send

The most accurate count comes back in the usage field after a request, and in the last chunk of a stream. For planning before a request, estimate. This helper uses the four-characters rule:

def est_tokens(text: str) -> int:
    return max(1, len(text) // 4)

def history_tokens(messages) -> int:
    # about 4 tokens of overhead per message for role and formatting
    return sum(est_tokens(m["content"]) + 4 for m in messages)

It is rough and tends to under-count non-English text, so leave a margin: aim to stay under about 80,000 tokens of input rather than 99,000. Then log the real prompt_tokens from the response and compare it with your estimate for a week. The gap tells you how much margin you need.

Trimming history in code

The simplest policy keeps the system message and drops the oldest turns until the estimate is under budget.

BUDGET = 60_000   # input tokens you are willing to send

def trim(messages, budget=BUDGET):
    system, rest = messages[0], messages[1:]
    while rest and history_tokens([system] + rest) > budget:
        rest.pop(0)
        # drop a leading assistant message so the chat starts on a user turn
        while rest and rest[0]["role"] == "assistant":
            rest.pop(0)
    return [system] + rest

Using a budget well below 100,000 is deliberate: it leaves room for the reply and keeps each request cheaper. If trimming ever removes something the user still cares about, such as a name or a promise made early in the chat, put that fact into the system message so it survives every cut. For stories where earlier events matter, add a summary step. When history passes a threshold, send the oldest half to the model with an instruction to write a compact recap, then store that recap as a second system message and delete the turns it replaced.

from openai import OpenAI
import os

client = OpenAI(base_url="https://api.nsfwllm.cc/v1",
                api_key=os.environ["NSFW_API_KEY"])

def summarize(old_messages):
    text = "\n".join(m["role"] + ": " + m["content"] for m in old_messages)
    r = client.chat.completions.create(
        model="uncensored",
        messages=[
            {"role": "system", "content": "Summarize this chat in under 200 words. Keep names, facts and open plot threads."},
            {"role": "user", "content": text},
        ],
        temperature=0.2,
    )
    return r.choices[0].message.content

What a full window costs

Input is billed at $0.15 per 1M tokens and output at $0.50 per 1M. Sending a completely full prompt of 100,000 tokens costs 100,000 / 1,000,000 x $0.15 = $0.015 per request, before any output. With a 300 token reply (300 / 1,000,000 x $0.50 = $0.00015), one turn costs about $0.01515. A hundred such turns come to roughly $1.52.

Compare that to a trimmed history of 10,000 tokens: $0.0015 for input plus $0.00015 for the reply, or $0.00165 per turn. One hundred turns cost $0.165. Trimming therefore cuts the cost of long chats by roughly nine tenths, and it often helps answer quality too.

There is no subscription. You prepay credit, failed or refused requests are not charged and the credit never expires. Top-ups are in crypto (USDT on TRC20 or USDC on Base) from $20 to $500, with +5% from $50, +10% from $100 and +15% from $200. See pricing.

Other ways to stay inside the window

  • Keep the system prompt short. It is resent every turn. See how a persona prompt is written in practice in the Dolphin LLM myths versus facts article.
  • Store facts outside the chat. A short list of key facts in the system message beats thousands of tokens of old dialogue.
  • Chunk long documents. Split a large text, process each chunk with the same instruction, and combine the results.
  • Retrieve instead of paste. Keep documents in your own store, search them yourself, and send only the passages that matter. This API has no embeddings endpoint, so use a separate tool for the search.
  • Limit output. Ask for brief replies when a long one is not needed. Output tokens cost more than input tokens.

Rate limits are separate from the window. A full key allows 8 concurrent requests and 300 per minute; going over returns HTTP 429. Very long prompts take longer to process, so a stream stays open longer and holds its concurrency slot until it ends.

Test your own limits

Rather than trusting a rule of thumb, run a quick experiment with real text from your app. Sign up, claim the $0.50 trial credit on the API key page (one click, valid for 7 days), and send prompts of growing size while printing usage. Note where the answers start to degrade for your use case. A trial credit covers a few dozen large requests, since a 50,000 token prompt costs $0.0075 in input.

The docs list the error codes and headers, and the open-source model API page explains what model sits behind the endpoint. It handles text only and is run by an independent provider; it is not an official API of any model vendor. Prompts are not used for training.

Questions and answers

How many words fit in 100,000 tokens?

About 75,000 English words, or roughly 150 pages at 500 words a page. Other languages and code use more tokens per word.

Does the limit include the model's reply?

Yes. The window is shared by the prompt and the completion, so a long prompt leaves less room for the answer.

What happens if my prompt is too long?

Treat it as an error and do not expect silent truncation. Failed requests are not charged, so trim or summarize the history and retry.

Is a bigger prompt better?

Not always. Cost rises with input size, and quality can drop in very long contexts. Send what the task needs.

Your key is one form away

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