How to Change Context Window in Ollama, or Skip It
How to change context window in Ollama comes down to the num_ctx option, set per request or in a Modelfile, and you pay for a bigger window in memory. If you would rather not tune it at all, a hosted endpoint with a fixed 100,000-token window removes the setting.
Updated
Key points
- In Ollama the window is set with num_ctx, per request through options or permanently through a Modelfile.
- A larger window uses more memory for the KV cache, so the limit is usually your hardware, not the setting.
- Silent truncation of long prompts is the classic symptom of a window that is too small.
- This API has a fixed 100,000-token window shared by prompt and completion, with no setting to change.

The quick answer for Ollama
If you came here to change the context window in Ollama, there are three places to do it, and they apply at different scopes. All of them control one number: how many tokens the model can see at once, counting your prompt and the reply it is writing.
- Per request. Pass
num_ctxinside theoptionsobject of a call to Ollama's native API. It applies to that request only. - Per model, permanently. Write a Modelfile with a line such as
PARAMETER num_ctx 16384and build a new model from it. Every chat with that model uses the larger window. - Inside an interactive session. In the Ollama CLI you can run
/set parameter num_ctx 16384while chatting.
Newer Ollama releases also expose a server-level default through an environment variable, and the default value itself has changed between versions, so check the current Ollama documentation for what your install does. The reliable habit is to set the value explicitly for any model you depend on.
The reason this setting exists is that the window is not free. The rest of this article explains what it costs, how to tell when yours is too small, and the alternative of calling a hosted endpoint where the window is already large.
Setting num_ctx in a Modelfile
The Modelfile route is the one most people want, because it survives restarts and works from any client that names the model. You write a short file, build a new model tag from your base model, and use that tag from then on.
# Modelfile contents (save as Modelfile):
# FROM your-base-model
# PARAMETER num_ctx 16384
#
# Build and run it:
ollama create my-model-16k -f Modelfile
ollama run my-model-16k
Replace your-base-model with whatever you have pulled. The new tag shares the weights with the base, so it takes almost no extra disk space. Only the parameter differs.
Choose the number with a plan. Doubling the window roughly doubles the memory the conversation cache needs. A value your model supports on paper may still not fit next to the weights on a card with limited VRAM, in which case the runner will spill layers to system RAM and generation slows down sharply. Raise the value in steps, run a long prompt, and watch memory before settling.
What the hosted call looks like
For a single long job on Ollama you can also pass num_ctx inside options on that one request and leave the model alone. The hosted alternative needs no such field, as this call to the API on this site shows.
from openai import OpenAI
client = OpenAI(base_url="https://api.ollamauncensored.top/v1", api_key="YOUR_KEY")
with open("long_report.txt", encoding="utf-8") as f:
document = f.read()
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You summarize documents in plain language."},
{"role": "user", "content": "Summarize this report in 10 bullets:\n\n" + document},
],
)
print(resp.choices[0].message.content)
There is no num_ctx field in that call. The hosted window is the same for every request, so a long document either fits or the request fails with a clear error, and there is no quiet cutting of the start of your text.
Why a bigger window costs memory
A language model reads your whole prompt, then writes one token at a time. To avoid recomputing the past at every step it stores intermediate values for every token seen so far. That store is the KV cache, and it grows in proportion to the number of tokens in the window. Longer window, bigger cache, more memory in use.
This is the part people miss when they raise num_ctx. The weights are a fixed size. The cache is the variable part, and it competes with the weights for the same VRAM. On a single consumer card, a model that runs well at a short window can become slow or fail to load at a long one.
Attention work also grows with length, so a very long prompt takes longer before the first token appears. That delay is the cost of reading everything, and it applies to hosted services too, only on hardware you do not have to manage.
| Window setting | What changes | Typical symptom of a bad fit |
|---|---|---|
| Too small | Old messages or the start of a long prompt are dropped | The model forgets instructions or ignores the first pages of a document |
| About right | Prompt and reply fit with some room left | None |
| Too large for the hardware | Cache competes with weights for memory | Slow generation, out-of-memory errors, layers moved to system RAM |
Signs your window is too small
A short window rarely announces itself. The runner trims the front of the prompt to make it fit, and the model answers whatever is left. You get a fluent reply built on missing information. Look for these patterns:
- A chatbot that stops following its system prompt after a long conversation, because the system message was the oldest content and got cut.
- A summary that covers only the end of a long document.
- Code review that cites functions from the bottom of a file and misses the top.
- Roleplay or story characters that forget details established early on.
A quick test: put a unique fact at the very start of a long prompt, such as "the password is plum", pad the rest with filler, then ask for it at the end. If the model cannot answer, the start is not reaching it.
Before blaming the window, check the other explanation, which is that the model simply did not use the information. A real truncation failure is consistent: move the fact to the end of the prompt and the model finds it every time.
How the hosted 100,000-token window works
The API on this site serves one model, uncensored, with a context window of 100,000 tokens. That budget covers the prompt and the completion together. If your prompt is 60,000 tokens, the reply can use up to the remaining 40,000. The max_tokens field is optional, so you do not have to compute the remainder yourself, though setting it caps the reply length when you want a short answer.
As a rough guide, English text runs near three quarters of a word per token, so 100,000 tokens is on the order of 75,000 words, a few hundred pages of plain prose. Code and non-English text usually consume more tokens per line or word, so leave a margin.
What you do not get is control. There is no dial to turn up or down. That is the trade: no tuning and no memory planning, but also no option to pick a window larger than the one served. If your use case needs more than 100,000 tokens in one request, you need to split the work, for example by summarizing in stages.
The request body can be up to 8 MB, which is far above what 100,000 tokens needs, so the token window is the limit you will hit first. Streaming works with stream: true, and the final chunk carries usage so you can see what each call actually consumed. The full parameter list is in the docs.
What a long window costs per request
Long prompts are billed by tokens like any other: $0.15 per 1M input tokens and $0.50 per 1M output tokens. A request that fills the window with 100,000 input tokens costs 100,000 x $0.15 / 1,000,000 = $0.015 for the input. Add a 1,000-token answer at 1,000 x $0.50 / 1,000,000 = $0.0005, and the call totals $0.0155.
The chat case is more interesting because history is resent every turn. Say a bot has a 500-token system prompt, and each turn adds 100 tokens from the user and 200 from the reply. Over 20 turns, the input tokens add up to 69,000 and the output to 4,000. That costs 69,000 x $0.15 / 1,000,000 = $0.01035 for input plus 4,000 x $0.50 / 1,000,000 = $0.002 for output, which is $0.01235 for the whole conversation.
The lesson is that trimming history saves money as well as space. If you want to compare plans, see the token pricing. Failed or refused requests are not charged, and credit never expires.
To test with a real long prompt, claim the trial credit after sign-up: $0.50, one click on the key page, no card, valid for 7 days. That is enough for more than 30 full-window requests at the $0.0155 figure above.
Choosing between local tuning and a hosted window
Stay with Ollama if you want everything on your own machine, your hardware has memory to spare, and you are fine managing num_ctx per model. You get full control, and nothing leaves the computer.
Consider the hosted route if your window needs exceed what your GPU holds, if the same prompt must work from several machines, or if you would rather pay by the token than buy memory. The code change is small, since both speak the OpenAI chat format: new base URL, new key, model uncensored. Many people keep both, local for quick private experiments and hosted for long-document jobs.
More guides
Questions and answers
What is the default context window in Ollama?
It has differed between releases, and newer versions let you set a server-wide default, so check the documentation for your installed version. Setting num_ctx explicitly for models you rely on avoids surprises.
Does a larger num_ctx make answers better?
Only when your input would otherwise be cut. A larger window lets the model see more, but it also uses more memory and slows prompt processing, so size it to the job.
How big is the context window on this API?
100,000 tokens, counting prompt and completion together. It is fixed and there is no parameter to change it.
Do I have to set max_tokens?
No. It is optional, and the completion can use whatever part of the 100,000-token window your prompt leaves free. Set it only if you want to cap the reply length.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.