EN ▾
Get API key

model_context_window: What 100k Tokens Gives You

The context window is the total number of tokens a model can read and write in one request. Here it is 100,000, and the prompt and the reply both count against it.

Updated

A ribbon of glowing tiles passing through a frame that is partly filled, illustrating a shared context window

What a context window is

When you see a field or setting called model_context_window in a config file, a client or a library, it holds one number: how many tokens the model can handle in a single request. A token is a piece of text, often a short word or a part of a longer one. English prose averages somewhere around three quarters of a word per token, so 100,000 tokens is roughly 75,000 words, though the real ratio depends on the text, and code, numbers and some languages use more tokens per word.

The key point is that the window is shared. Everything the model reads, which is your system prompt, the chat history, any pasted documents and your new message, sits in the same space as everything it writes back. On this API the limit is 100,000 tokens for prompt plus completion combined. If your prompt is 90,000 tokens, the reply can be at most about 10,000.

The model has no memory between requests. When a chat feels continuous, it is because your client sends the earlier messages again each time. The window is the size of the page you hand over on every call, nothing more.

How the limit works on this API

The context window is 100,000 tokens, and the completion can use all the space the prompt leaves. The max_tokens parameter is optional. If you leave it out, the model writes until it finishes naturally or until it runs out of window. If you set it, it acts as a cap on the reply, which is useful when you want short answers or want to bound the output cost.

Two practical consequences follow:

  • A request whose prompt alone is larger than the window cannot succeed. Count before you send when documents come from users.
  • You pay for the tokens actually generated, at $0.50 per 1M output tokens, so a short answer costs little even when the window is large.

The request body has its own limit of 8 MB. For plain text that is far more than 100,000 tokens, so the token window is the one you will meet first. The two limits matter mostly if you embed large binary-looking data in a message, which is a bad idea anyway.

The response includes a usage block with prompt and completion token counts, and with streaming (stream: true) the usage arrives at the end of the stream. Log it. It is the most honest measure of how close you are running to the limit.

Counting tokens before you send

You can estimate the size of a prompt without a tokenizer by dividing the character count by four, which is a rough rule for English. For anything near the limit, measure instead. Send the request and read usage.prompt_tokens from the response, or keep a running tally from earlier replies. The code below keeps a chat history, reads the usage field and warns when the prompt is getting large.

from openai import OpenAI

client = OpenAI(base_url="https://api.nsfwmodel.top/v1", api_key="YOUR_API_KEY")

WINDOW = 100_000
history = [{"role": "system", "content": "You are a patient co-writer."}]

def ask(text):
    history.append({"role": "user", "content": text})
    resp = client.chat.completions.create(model="uncensored", messages=history)
    reply = resp.choices[0].message.content
    history.append({"role": "assistant", "content": reply})
    used = resp.usage.prompt_tokens + resp.usage.completion_tokens
    if used > 0.8 * WINDOW:
        print(f"warning: {used} of {WINDOW} tokens used")
    return reply

print(ask("Outline a three-act story about a lighthouse keeper."))

If you want exact counts ahead of time, a tokenizer library for the model's family can give them, but the figure may differ slightly from what the server uses. Treat client-side counts as estimates and the response's usage as the final number. Leave a margin of at least a few thousand tokens so the reply has room.

What it costs to fill the window

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, billed from prepaid credit. Because of this split, long prompts are cheap compared with long replies. Here are exact figures.

RequestInput costOutput costTotal
80,000 in, 4,000 out0.08 x $0.15 = $0.01200.004 x $0.50 = $0.0020$0.0140
50,000 in, 50,000 out0.05 x $0.15 = $0.00750.05 x $0.50 = $0.0250$0.0325
10,000 in, 1,000 out0.01 x $0.15 = $0.00150.001 x $0.50 = $0.0005$0.0020

So even a request that nearly fills the window costs about a cent and a half. The expensive pattern is not one big call. It is thousands of medium calls that each resend a large history. Failed or refused requests are not charged, and credit never expires, so there is no penalty for cautious experiments. See the pricing page for top-ups, which run from $20 to $500 in whole amounts.

Why chats get more expensive each turn

Take a chat with a 1,000-token system prompt. Each turn the user writes about 600 tokens and the model replies with about 400. After every turn the history grows by 1,000 tokens. The input on turn k is therefore 1,000 x k + 600 tokens, because the system prompt and all earlier exchanges are resent, plus the new message.

Over 20 turns the inputs add up to 1,000 x (1 + 2 + ... + 20) + 600 x 20 = 210,000 + 12,000 = 222,000 tokens. The outputs add up to 400 x 20 = 8,000 tokens. The cost is 0.222 x $0.15 + 0.008 x $0.50 = $0.0333 + $0.0040 = about $0.037 for the whole conversation. The last turn sends 20,600 tokens, which is nowhere near the window.

The effect is quadratic in the number of turns. Double the conversation to 40 turns and the input total does not double, it roughly quadruples. That is why a long roleplay session or a coding agent that keeps every tool result can burn through tokens faster than expected, even though each single request stays within the limit.

Using long context well

A big window is useful, but filling it is rarely the goal. Models tend to attend less reliably to material buried in the middle of a very long prompt, so a focused prompt often beats a stuffed one. These tactics work across most setups:

  • Put the instructions first and repeat the key ask last. The start and the end of a prompt are the parts most likely to be followed.
  • Summarize old turns. Replace the oldest part of a chat with a short summary written by the model itself, and keep the recent messages verbatim.
  • Use a sliding window. Keep the system prompt plus the last N messages, and drop the rest.
  • Pin what must not be forgotten. Character sheets, story facts and rules go in the system message, which you never trim.
  • Trim tool output. An agent that pastes a 30,000-token log into every later step wastes the window. Pass a cut-down version.

For long-form writing, such as a novel draft or a multi-part story for adult readers, the window lets you keep the outline, character notes and the last several chapters in view at once. For agent tasks it lets a workflow carry many tool results before it needs pruning. In both cases, plan the pruning before you need it.

Limits that sit next to the window

The context window is not the only ceiling. Concurrency and rate limits shape how a large workload behaves. A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 per minute. A streamed request holds its slot until the stream finishes, and a long completion can take a while. Exceeding a limit returns HTTP 429, with the code rate_limited or concurrency. Under temporary overload you also get a 429 with a Retry-After: 5 header.

The service is text only and has no embeddings, so if you want to search a large document collection and pass only the relevant parts to the model, you need an outside source for the vector step. Details of each parameter are in the quickstart docs, and the NSFW LLM API overview describes the service itself. To test with real token counts, claim the $0.50 trial credit on the API key page. It needs no payment details and is valid for 7 days. Prompts are not used for training.

Questions and answers

How big is the context window?

It is 100,000 tokens, counting the prompt and the completion together. A longer prompt leaves less room for the reply.

Do I have to set max_tokens?

No, it is optional. Without it the reply can use all of the window the prompt leaves. Set it only if you want to cap the length or the output cost.

Am I charged for tokens I do not use?

No. You pay for the input tokens you send and the output tokens generated, at $0.15 and $0.50 per 1M. Failed or refused requests are not charged.

What happens if my prompt is too long?

A prompt that exceeds the window cannot be completed. Shorten it by trimming history or splitting the document before you send it.

Is 100,000 tokens enough for a book?

It fits roughly 75,000 English words in one request, depending on the text. A full novel needs chunking or summaries, since the window is shared with the reply.

Your key is one form away

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

Get API keyRead the docs