EN ▾
Get API key

nsfwllms.comGuide

Context Window for LLMs: Size, Cost and Limits

A context window is the number of tokens a model can read and write in a single request. On this API it is 100,000 tokens, with the prompt and the reply sharing that space.

Updated

Key points

  1. The window covers everything: system prompt, chat history, your new message and the reply.
  2. 100,000 tokens is roughly 75,000 English words, enough for a long roleplay history or a book-length document.
  3. The API is stateless, so you resend history each call and pay input price for it every time.
  4. A 40,000-token history plus a 500-token reply costs about $0.0063 per request.
Glowing scroll passing through a frame, with older blocks fading out, illustrating a context window

What the window actually holds

The context window for LLMs is the model's working memory for one request. It is measured in tokens, which are chunks of text a little shorter than an average word. Everything the model sees and everything it writes has to fit inside it.

That includes more than your latest message. A typical chat request carries four things:

  • the system prompt, where you describe the persona, rules and style;
  • every earlier user and assistant message you choose to include;
  • any documents, notes or retrieved snippets you paste in;
  • the completion the model is about to produce.

Whatever you leave out, the model does not remember. The API keeps no session between calls, so your application owns the history. This is the same for every OpenAI-compatible endpoint, and it is why the window size shapes how you design a chat app.

How far 100,000 tokens goes

For English prose, one token is about three quarters of a word. Other languages and code usually use more tokens per word, so treat these numbers as rough guides, not promises.

TokensApprox. English wordsWhat it looks like
1,000750A long system prompt or a short scene
10,0007,500A multi-hour chat or a long article
50,00037,500A short novel's first act
100,00075,000The full window, prompt plus reply

A quick sanity check on your own data: take a typical conversation from your app, count its characters and divide by four. If the result is under 20,000 tokens, you are using a fifth of the window and have no reason to compress anything yet.

The window is shared. If your prompt takes 98,000 tokens, only about 2,000 are left for the answer. max_tokens is optional on this API, and the completion may use whatever space remains, so leave headroom when you pack the prompt.

Where a large window pays off

Long context matters most when continuity is the product. Three cases come up again and again.

Long-running fiction and companion apps

Adults who use roleplay or companion apps notice quickly when a character forgets a name, a promise or a location. A big window lets you keep weeks of conversation in the prompt instead of squeezing it into a one-paragraph summary. Keep the summary anyway for very old events, but you can stop compressing so aggressively.

Document work

You can paste a long manuscript, a transcript or a set of notes and ask for edits, a continuity check or a rewrite in a different voice. For text that fits, this is simpler than building a retrieval pipeline.

Agents with tools

Tool results pile up fast. A loop that calls a search function ten times can add tens of thousands of tokens of output. Room to spare keeps the loop from failing halfway through a task.

What a long prompt costs

Pricing is per token: $0.15 per 1M input tokens and $0.50 per 1M output tokens. A big window does not cost anything by itself. You pay for the tokens you actually send, and since history is resent on every call, the input side grows with each turn.

Worked example: a roleplay session where the history has reached 40,000 tokens. You send a 500-token message and get a 500-token reply.

  • Input: 40,500 tokens x $0.15 / 1,000,000 = $0.006075
  • Output: 500 tokens x $0.50 / 1,000,000 = $0.00025
  • Total: $0.006325 per exchange, so 100 exchanges cost about $0.63.

The most extreme case is a prompt that fills the window: 100,000 input tokens cost $0.015. Even then a $20 top-up covers well over a thousand such calls. Failed or refused requests are not charged. Current rates and top-up bonuses are on the pricing page.

Keeping history under the cap

Do not wait for the window to fill. Trim on purpose, and keep the system prompt and the most recent turns. This sketch drops the oldest messages once a rough budget is exceeded. It estimates tokens from character count, which is good enough for a guard rail and cheap to run.

from openai import OpenAI

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

BUDGET = 60_000  # leave room for the reply

def approx_tokens(text: str) -> int:
    return len(text) // 4

def trim(messages, budget=BUDGET):
    system, rest = messages[0], list(messages[1:])
    def total():
        return sum(approx_tokens(m["content"]) for m in [system] + rest)
    while rest and total() > budget:
        rest.pop(0)
    return [system] + rest

history = [{"role": "system", "content": "You are a patient storyteller."}]
history.append({"role": "user", "content": "Continue the story from the lighthouse."})

resp = client.chat.completions.create(
    model="uncensored",
    messages=trim(history),
)
print(resp.choices[0].message.content)
print(resp.usage)  # check real prompt_tokens against your estimate

Compare resp.usage.prompt_tokens with your estimate for a few real conversations and adjust the divisor. For a smarter approach, ask the model to summarize the oldest block of messages, store that summary, and replace the block with it. The quickstart documentation covers the basic request shape this builds on.

Pitfalls with long context

  • Burying instructions. Models tend to follow text near the start and end of a long prompt more reliably than text in the middle. Put the rules in the system prompt and repeat any critical one near the end.
  • Forgetting the reply. A prompt of 99,000 tokens leaves almost nothing for the answer. Trim to a budget well below the cap.
  • Paying for dead weight. Old greetings, repeated boilerplate and unused tool output all cost input tokens on every call. Prune them.
  • Request size. The maximum body is 8 MB. That is far above what 100,000 tokens of text needs, but base64 attachments or huge pasted logs can hit it.
  • Concurrency. A full key allows 8 concurrent requests. Large prompts take longer to process, so a burst of them ties up slots; queue them on your side.

If you want to try these patterns on real traffic, the API key page lets new accounts claim $0.50 of trial credit with one click, so you can test before paying anything. For a chat-style integration, see the chat integration page.

Questions and answers

What is the context window of this API?

100,000 tokens, counted across the prompt and the completion together. Max body size is 8 MB.

Does a bigger context window cost more?

Not by itself. You pay $0.15 per 1M input tokens and $0.50 per 1M output tokens for what you actually send and receive, so a short prompt costs the same whatever the window size.

Does the model remember earlier conversations?

No. Each request is independent, so your app must send the earlier messages you want the model to use.

How many words fit in 100,000 tokens?

Roughly 75,000 English words. Code and non-English text use more tokens per word, so expect less.

Your key is one form away

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

Get API key