<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Davidrs</title>
    <description>The latest articles on DEV Community by Davidrs (@davidrscout).</description>
    <link>https://dev.to/davidrscout</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4264439%2Fbe59654a-993e-4293-b700-b2e0e64f30b5.png</url>
      <title>DEV Community: Davidrs</title>
      <link>https://dev.to/davidrscout</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidrscout"/>
    <language>en</language>
    <item>
      <title>Ollama returns an empty response after 60 seconds? The model spent the context thinking</title>
      <dc:creator>Davidrs</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:00:04 +0000</pubDate>
      <link>https://dev.to/davidrscout/ollama-returns-an-empty-response-after-60-seconds-the-model-spent-the-context-thinking-5g1f</link>
      <guid>https://dev.to/davidrscout/ollama-returns-an-empty-response-after-60-seconds-the-model-spent-the-context-thinking-5g1f</guid>
      <description>&lt;p&gt;We had a small script that turns meeting minutes into a JSON task list. It called &lt;code&gt;qwen3.5:9b&lt;/code&gt; through Ollama's OpenAI-compatible endpoint (&lt;code&gt;/v1/chat/completions&lt;/code&gt;), the same endpoint most apps and SDKs use. Every call hung for about a minute and then came back with nothing. Our code then failed with "the response is not valid JSON", which sent us looking at the parser first.&lt;/p&gt;

&lt;p&gt;Ollama hadn't errored and the model hadn't crashed. It had reasoned until it ran out of room, and there was no context left for the answer.&lt;/p&gt;

&lt;p&gt;Setup: Windows 11, 16 GB RTX 5060 Ti, Ollama 0.40.14.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tell: usage adds up to the context
&lt;/h2&gt;

&lt;p&gt;The response body had an empty &lt;code&gt;content&lt;/code&gt;, but the usage counters were not empty at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;completion_tokens: 3661     total_tokens: 4096
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thousands of generated tokens and an empty string. &lt;code&gt;total_tokens&lt;/code&gt; is exactly 4,096, which is the context Ollama chose for that GPU. The server log says the same thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompt eval time =   255.53 ms /   435 tokens
       eval time = 59558.53 ms /  3661 tokens
      total time = 59814.06 ms /  4096 tokens
stop processing: n_tokens = 4095, truncated = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it from top to bottom: 435 tokens of prompt (minutes plus instructions), then 3,661 tokens generated over almost 60 seconds, all of it hidden reasoning, until the window was full. &lt;code&gt;truncated = 1&lt;/code&gt; means generation stopped at the limit, not because the model finished.&lt;/p&gt;

&lt;p&gt;So the pattern to look for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Latency far above normal (here ~60 s).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;content&lt;/code&gt; empty or blank.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;prompt_tokens + completion_tokens&lt;/code&gt; equals the context size.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;truncated = 1&lt;/code&gt; at the end of the request in the log.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you use the native API (&lt;code&gt;/api/chat&lt;/code&gt;) with thinking on, the reasoning comes back in a separate &lt;code&gt;thinking&lt;/code&gt; field. A full &lt;code&gt;thinking&lt;/code&gt; and an empty &lt;code&gt;content&lt;/code&gt; is the same diagnosis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a 4k context makes this so easy to hit
&lt;/h2&gt;

&lt;p&gt;Models like &lt;code&gt;qwen3.5&lt;/code&gt; think by default: they write a reasoning trace before the answer, and those tokens occupy context exactly like your prompt does. On a GPU with less than 24 GiB of VRAM, Ollama's default context is 4,096 (the log prints it at startup in the &lt;code&gt;vram-based default context&lt;/code&gt; line). A 435-token prompt leaves about 3,600 tokens for thinking plus answering, and the model used all of it thinking.&lt;/p&gt;

&lt;p&gt;How much a model reasons is hard to predict. With a much larger model on a different local server we measured 54,512 tokens of hidden reasoning for a single answer. This isn't a rare bug. Reasoning models do this unless something limits them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: check whether your model reasons
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'qwen3.5:9b'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ConvertTo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;RestMethod&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;11434&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt; &lt;span class="nv"&gt;$m&lt;/span&gt; &lt;span class="sb"&gt;`
  -ContentType 'application/json').capabilities
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;thinking&lt;/code&gt; is in the list, the model reasons. If it isn't, the switches below do nothing and your empty reply has another cause (more on that at the end).&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: turn reasoning off, per API
&lt;/h2&gt;

&lt;p&gt;The switch depends on how you call Ollama:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Interface&lt;/th&gt;
&lt;th&gt;Switch&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;/v1/chat/completions&lt;/code&gt; (OpenAI-compatible)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"reasoning_effort": "none"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;/api/chat&lt;/code&gt;, &lt;code&gt;/api/generate&lt;/code&gt; (native)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"think": false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CLI&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ollama run qwen3.5:9b --think=false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inside an &lt;code&gt;ollama run&lt;/code&gt; session&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/set nothink&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We tested the first two on 0.40.14. The CLI options come from Ollama's &lt;a href="https://docs.ollama.com/capabilities/thinking" rel="noopener noreferrer"&gt;thinking docs&lt;/a&gt; and announcement. &lt;code&gt;gpt-oss&lt;/code&gt; takes levels (&lt;code&gt;low&lt;/code&gt;, &lt;code&gt;medium&lt;/code&gt;, &lt;code&gt;high&lt;/code&gt;) rather than on/off, per the same docs.&lt;/p&gt;

&lt;p&gt;Don't use &lt;code&gt;--hidethinking&lt;/code&gt; for this. According to Ollama's announcement it only hides the trace on screen. The model still reasons and still spends context.&lt;/p&gt;

&lt;p&gt;Here's the request that fixed our script, in PowerShell. On Windows, &lt;code&gt;curl&lt;/code&gt; in PowerShell is a different command and handles JSON quoting badly, so we use &lt;code&gt;Invoke-RestMethod&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'qwen3.5:9b'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="n"&gt;reasoning_effort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'none'&lt;/span&gt;
  &lt;span class="n"&gt;response_format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'json_object'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;(&lt;/span&gt;
    @&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'system'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Return only JSON: {"actions":[{"action":"","owner":""}]}'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    @&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Marta will review the inventory. Lucia is preparing the draft.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ConvertTo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Depth&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="nv"&gt;$r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;RestMethod&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;11434&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="sb"&gt;`
  -Body ([Text.Encoding]::UTF8.GetBytes($body)) -ContentType 'application/json'
$r.choices[0].message.content
$r.usage
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same minutes that used to time out at 60 s came back in &lt;strong&gt;3.6 seconds&lt;/strong&gt; with valid JSON.&lt;/p&gt;

&lt;p&gt;For the native API, the equivalent is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'qwen3.5:9b'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;think&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$false&lt;/span&gt;
  &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;(&lt;/span&gt;@&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Summarize in one sentence: the meeting is postponed to Monday.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ConvertTo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Depth&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;RestMethod&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Uri&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;11434&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ContentType&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt; &lt;span class="nv"&gt;$body&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3 (alternative): keep reasoning, give it room
&lt;/h2&gt;

&lt;p&gt;For multi-step problems you may want the reasoning. In that case the prompt, the trace and the answer all have to fit. The OpenAI-compatible endpoint won't take &lt;code&gt;num_ctx&lt;/code&gt; per request, so either raise it server-wide or bake it into a model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM qwen3.5:9b
PARAMETER num_ctx 16384
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;ollama&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;qwen9b&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;16k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="nc"&gt;Modelfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the native API you can pass &lt;code&gt;"options": { "num_ctx": 16384 }&lt;/code&gt; per request, or set &lt;code&gt;OLLAMA_CONTEXT_LENGTH&lt;/code&gt; before starting &lt;code&gt;ollama serve&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Throughput barely suffers. At 32,768 of context we measured 86, 55 and 80 tokens/s for &lt;code&gt;qwen3.5:4b&lt;/code&gt;, &lt;code&gt;qwen3.5:9b&lt;/code&gt; and &lt;code&gt;gemma4:12b&lt;/code&gt;. The real cost is VRAM, and wall-clock time, because every answer takes as long as the model decides to think. We didn't measure how much &lt;code&gt;qwen3.5:9b&lt;/code&gt; reasons with that extra room, so put a timeout on the call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: stop failing silently
&lt;/h2&gt;

&lt;p&gt;The worst part of this bug was that our program saved a blank row and moved on. Make empty content fail loudly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"the model returned an empty response (did it run out of context while thinking?)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  While you're there: "almost JSON"
&lt;/h2&gt;

&lt;p&gt;The second failure in the same script was JSON that looked right but didn't parse. When we only asked for JSON in the prompt, &lt;code&gt;qwen3.5:9b&lt;/code&gt; occasionally wrote a number with a leading zero (&lt;code&gt;"turno": 01&lt;/code&gt; in our Spanish test), which isn't valid JSON. Requesting the format through the API instead of in prose fixed it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/v1&lt;/code&gt;: &lt;code&gt;response_format: { "type": "json_object" }&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;native: &lt;code&gt;"format": "json"&lt;/code&gt; (or a full JSON schema)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the format forced, three models across five cases and three repetitions each gave &lt;strong&gt;45 valid responses out of 45&lt;/strong&gt;. It also helped accuracy: &lt;code&gt;qwen3.5:9b&lt;/code&gt; went from 16 to 23 of 27 criteria on one test, and from 14 to 21 of 24 on the minutes-to-tasks one.&lt;/p&gt;

&lt;p&gt;Valid JSON isn't correct JSON, though. Even with valid output, &lt;code&gt;qwen3.5:9b&lt;/code&gt; left owner and due-date fields blank instead of writing "PENDING" as instructed, and our validator raised 4 warnings. &lt;code&gt;gemma4:12b&lt;/code&gt; passed the same minutes with no warnings, in 11.2 s. Keep validating fields in code.&lt;/p&gt;

&lt;h2&gt;
  
  
  If it's not reasoning
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The prompt doesn't fit.&lt;/strong&gt; An agent like OpenCode sent about 23k tokens into a 4,096 context, and Ollama truncated it without an error. See &lt;a href="https://beautythings.net/en/guides/opencode-ollama-not-working/?s=devto" rel="noopener noreferrer"&gt;OpenCode with Ollama not working&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The model doesn't support &lt;code&gt;think&lt;/code&gt;.&lt;/strong&gt; Check &lt;code&gt;/api/show&lt;/code&gt;. If there's no &lt;code&gt;thinking&lt;/code&gt; capability, the switch changes nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The model never loaded.&lt;/strong&gt; A model larger than your VRAM can end in a 500. See &lt;a href="https://beautythings.net/en/guides/ollama-error-500-unable-to-load-model/?s=devto" rel="noopener noreferrer"&gt;Ollama error 500 "unable to load model"&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Full measurements and configs: &lt;a href="https://beautythings.net/en/guides/ollama-empty-response-thinking/?s=devto" rel="noopener noreferrer"&gt;https://beautythings.net/en/guides/ollama-empty-response-thinking/?s=devto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wrote the whole setup up as a short book: &lt;a href="https://beautythings.net/go/ollama-en?s=devto" rel="noopener noreferrer"&gt;https://beautythings.net/go/ollama-en?s=devto&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ollama</category>
      <category>llm</category>
      <category>ai</category>
      <category>windows</category>
    </item>
    <item>
      <title>OpenCode + Ollama does nothing? It's the 4,096-token context</title>
      <dc:creator>Davidrs</dc:creator>
      <pubDate>Wed, 25 Nov 2026 09:59:29 +0000</pubDate>
      <link>https://dev.to/davidrscout/opencode-ollama-does-nothing-its-the-4096-token-context-4fkd</link>
      <guid>https://dev.to/davidrscout/opencode-ollama-does-nothing-its-the-4096-token-context-4fkd</guid>
      <description>&lt;p&gt;You point OpenCode at a local Ollama model, ask it to read a file, and it tells you it has no access to files. Or it starts working on a feature nobody asked for. Or it loops on the same tool until it times out. No error anywhere.&lt;/p&gt;

&lt;p&gt;We hit all three on a Windows 11 box with a 16 GB RTX 5060 Ti (OpenCode 1.19.5, Ollama 0.40.14). The model wasn't the problem, and neither was OpenCode. The model never saw the request.&lt;/p&gt;

&lt;h2&gt;
  
  
  The mismatch
&lt;/h2&gt;

&lt;p&gt;Every OpenCode request carries a large preamble: the system prompt, the schema of every tool (read, glob, write, bash...), plus whatever your config adds, such as &lt;code&gt;AGENTS.md&lt;/code&gt;, skills and MCP servers. In our runs a single request weighed about &lt;strong&gt;23,000 tokens&lt;/strong&gt; before the user message was even relevant.&lt;/p&gt;

&lt;p&gt;Ollama picks a default context based on VRAM. Per its &lt;a href="https://docs.ollama.com/context-length" rel="noopener noreferrer"&gt;context length docs&lt;/a&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;VRAM&lt;/th&gt;
&lt;th&gt;Default context&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&amp;lt; 24 GiB&lt;/td&gt;
&lt;td&gt;4k&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;24-48 GiB&lt;/td&gt;
&lt;td&gt;32k&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&amp;gt;= 48 GiB&lt;/td&gt;
&lt;td&gt;256k&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Almost every consumer card lands in the first row. So you're sending ~23k tokens into a 4,096-token window, and Ollama doesn't reject the request. It trims it and carries on.&lt;/p&gt;

&lt;p&gt;It's worse than 4,096, too. With a 4k context the log showed an input limit of 2,050-2,051 tokens, because roughly half is reserved for the output. The model got about 2k tokens out of 22k, less than a tenth of what OpenCode meant to send.&lt;/p&gt;

&lt;p&gt;What that looked like in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;gemma4:12b&lt;/code&gt; started planning a "Remember Me" checkbox for a login form that doesn't exist, called its todo tool 65 times and ran into our 400-second timeout.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;qwen3.5:9b&lt;/code&gt; answered that it couldn't access files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Confirm it in the log
&lt;/h2&gt;

&lt;p&gt;Don't guess. The evidence is in the server log. With the tray app it lives at &lt;code&gt;%LOCALAPPDATA%\Ollama\server.log&lt;/code&gt;. With &lt;code&gt;ollama serve&lt;/code&gt; it goes to stderr.&lt;/p&gt;

&lt;p&gt;At startup, look for the default Ollama chose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;msg="vram-based default context" total_vram="15.9 GiB" default_num_ctx=4096
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And during the OpenCode session, look for this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;level=WARN source=llama_server.go:344 msg="truncating input prompt" limit=2051 prompt=22207 keep=5 new=2051
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That warning showed up 66 times in a single test run. To pull it out in PowerShell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"$env:LOCALAPPDATA\Ollama\server.log"&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="nv"&gt;$log&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Pattern&lt;/span&gt; &lt;span class="s1"&gt;'truncating input prompt'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Count&lt;/span&gt;
&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="nv"&gt;$log&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Pattern&lt;/span&gt; &lt;span class="s1"&gt;'n_ctx_slot = \d+'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Last&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="nv"&gt;$log&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Pattern&lt;/span&gt; &lt;span class="s1"&gt;'task\.n_tokens = \d+'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;ForEach&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Matches&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line counts truncations (you want 0). The second shows the context the model was actually loaded with. The third lists the size of each request OpenCode sent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix it on the Ollama side
&lt;/h2&gt;

&lt;p&gt;The catch is that OpenCode talks to Ollama through the OpenAI-compatible endpoint (&lt;code&gt;/v1&lt;/code&gt;), and Ollama's docs say that endpoint doesn't let you set the context per request. The &lt;code&gt;num_ctx&lt;/code&gt; option you'd pass to &lt;code&gt;/api/generate&lt;/code&gt; doesn't apply there. You have three ways to set it, and all of them take effect when the model loads, not mid-session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Environment variable on the server process&lt;/strong&gt; (the one we tested):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Process&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="s1"&gt;'ollama'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ollama app'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ErrorAction&lt;/span&gt; &lt;span class="nc"&gt;SilentlyContinue&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Process&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Force&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;OLLAMA_CONTEXT_LENGTH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'32768'&lt;/span&gt;
&lt;span class="n"&gt;ollama&lt;/span&gt; &lt;span class="n"&gt;serve&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;\&lt;span class="n"&gt;logs&lt;/span&gt;\&lt;span class="n"&gt;ollama&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Killing the tray app first matters. If an Ollama is already running, it answers your requests and never sees the variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. User environment variable&lt;/strong&gt;, if you prefer the tray app. On Windows it inherits user variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;SetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'OLLAMA_CONTEXT_LENGTH'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'32768'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'User'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quit Ollama from the tray and start it again from the Start menu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Bake &lt;code&gt;num_ctx&lt;/code&gt; into a model variant with a Modelfile.&lt;/strong&gt; This is what Ollama's docs suggest for &lt;code&gt;/v1&lt;/code&gt; clients:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM gemma4:12b
PARAMETER num_ctx 32768
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;ollama&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;gemma4&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;12b&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;32k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="nc"&gt;Modelfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then reference &lt;code&gt;ollama/gemma4-12b-32k&lt;/code&gt; in OpenCode. You'll need one variant per model and size. We didn't run this path ourselves, so check &lt;code&gt;ollama ps&lt;/code&gt; after you switch.&lt;/p&gt;

&lt;p&gt;However you set it, verify with the model loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;ollama&lt;/span&gt; &lt;span class="n"&gt;ps&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;CONTEXT&lt;/code&gt; column should read &lt;code&gt;32768&lt;/code&gt; and &lt;code&gt;PROCESSOR&lt;/code&gt; should say &lt;code&gt;100% GPU&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One thing that confused us: with the variable set, the log &lt;em&gt;still&lt;/em&gt; prints &lt;code&gt;default_num_ctx=4096&lt;/code&gt;. That's the value Ollama would have picked on its own. The variable takes precedence. Trust &lt;code&gt;n_ctx_slot&lt;/code&gt; and &lt;code&gt;ollama ps&lt;/code&gt;, not that line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tell OpenCode the same number
&lt;/h2&gt;

&lt;p&gt;Ollama needs the context, and OpenCode needs to know about it. Here is the minimal project-level &lt;code&gt;opencode.json&lt;/code&gt; we used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://opencode.ai/config.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ollama/gemma4:12b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"small_model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ollama/gemma4:12b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"enabled_providers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ollama"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"provider"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"ollama"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"npm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"@ai-sdk/openai-compatible"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Ollama (local)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"baseURL"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"http://127.0.0.1:11434/v1"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"models"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"gemma4:12b"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"gemma4 12B local"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"tool_call"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"limit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;32768&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"input"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28672&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"output"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4096&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;limit.context&lt;/code&gt; doesn't change anything in Ollama. It tells OpenCode when to compact the conversation. If you declare more than Ollama really has, OpenCode compacts too late and Ollama truncates silently again. If you're unsure, declare less.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;small_model&lt;/code&gt; explicitly. OpenCode uses it for things like session titles, and a &lt;code&gt;small_model&lt;/code&gt; in your global config gets merged into the project. In one run, a cloud &lt;code&gt;small_model&lt;/code&gt; from our global config opened an HTTPS connection to that provider while the "local" agent was working.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How much context do you actually need?
&lt;/h2&gt;

&lt;p&gt;The numbers we measured:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With 32,768, nothing was truncated, the agent used its tools, and &lt;code&gt;gemma4:12b&lt;/code&gt; wrote the requested file in 27 seconds.&lt;/li&gt;
&lt;li&gt;Requests grow with every turn. Across four requests for a single small task, &lt;code&gt;gemma4:12b&lt;/code&gt; went from 22,207 to 22,919 tokens. &lt;code&gt;qwen3.5:9b&lt;/code&gt; sent 23,004 and then 23,399 (each tokenizer counts differently). A real multi-file task grows much faster.&lt;/li&gt;
&lt;li&gt;Most of the weight is your config. With an empty global config, the first request was 7,440 tokens. With a daily-driver config (AGENTS.md, skills, a browser MCP server), it was 23,569. Even the clean version doesn't fit in 4,096.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ollama's docs recommend at least 64k for agents and coding tools, and the Ollama + OpenCode integration page asks for 64k or more. OpenCode's own docs suggest starting at 16k-32k if tools don't work. We only validated 32,768. Treat it as a floor that works, and go up if your VRAM allows.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VRAM:&lt;/strong&gt; &lt;code&gt;gemma4:12b&lt;/code&gt; at 32,768 sat around 8.4 GB while working with OpenCode. If you push the context past what fits, Ollama spills to system RAM and speed collapses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation speed:&lt;/strong&gt; barely affected. On a long prompt at 32k we measured 86, 55 and 80 tokens/s for &lt;code&gt;qwen3.5:4b&lt;/code&gt;, &lt;code&gt;qwen3.5:9b&lt;/code&gt; and &lt;code&gt;gemma4:12b&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;First-request latency:&lt;/strong&gt; reading OpenCode's first 22,207-token request took &lt;code&gt;gemma4:12b&lt;/code&gt; 12.7 s. The next request reused the cache, so Ollama processed only 58 new tokens in 0.37 s. If you switch models, restart Ollama or let the model unload, you pay the 12.7 s again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Kill every Ollama process, start it with &lt;code&gt;OLLAMA_CONTEXT_LENGTH=32768&lt;/code&gt; (or use a &lt;code&gt;num_ctx&lt;/code&gt; Modelfile).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ollama ps&lt;/code&gt; shows 32768 in &lt;code&gt;CONTEXT&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opencode.json&lt;/code&gt; declares the same number in &lt;code&gt;limit.context&lt;/code&gt;, with &lt;code&gt;limit.input&lt;/code&gt; below it, and &lt;code&gt;small_model&lt;/code&gt; points to the local model.&lt;/li&gt;
&lt;li&gt;Zero &lt;code&gt;truncating input prompt&lt;/code&gt; lines in the log since startup.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If all four pass and the agent still gets things wrong, the context isn't the problem anymore. A 9-12B model with a working context will use its tools, but it won't necessarily get the answer right. That's a separate problem.&lt;/p&gt;




&lt;p&gt;Full measurements and configs: &lt;a href="https://beautythings.net/en/guides/opencode-ollama-not-working/?s=devto" rel="noopener noreferrer"&gt;https://beautythings.net/en/guides/opencode-ollama-not-working/?s=devto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wrote the whole setup up as a short book: &lt;a href="https://beautythings.net/go/opencode-en?s=devto" rel="noopener noreferrer"&gt;https://beautythings.net/go/opencode-en?s=devto&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opencode</category>
      <category>ollama</category>
      <category>llm</category>
      <category>windows</category>
    </item>
  </channel>
</rss>
