Skip to content

Ollama integration: API returns HTTP 200 but responses not displayed #4488

Closed

Description

@guglielmo

Problem

OpenCode fails to display responses from Ollama despite successful API calls. Ollama returns HTTP 200, but no output appears in the terminal.

Environment

  • OpenCode: 1.0.78
  • Ollama: Latest (verified working via Postman/curl)
  • Models tested: qwen2.5-coder:7b-32k, qwen2.5:7b, deepseek-coder-v2:16b
  • System: Linux, 31GB RAM

Configuration

Using official docs configuration with @ai-sdk/openai-compatible:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "qwen2.5-coder:7b-32k": {
          "name": "Qwen 2.5 Coder 7B (32k context)"
        }
      }
    }
  }
}

Observed Behavior

Pattern across all tested providers (ollama-ai-provider-v2, ai-sdk-ollama, @ai-sdk/openai-compatible):

  1. OpenCode makes request to Ollama
  2. Ollama responds with HTTP 200 (verified in logs)
  3. OpenCode doesn't display response
  4. Second request follows (retry logic?)
  5. Second request times out or returns HTTP 500

Ollama logs:

[GIN] 2025/11/19 - 10:24:16 | 200 | 16.389317258s | POST "/v1/chat/completions"
[GIN] 2025/11/19 - 10:25:36 | 500 | 1m36s | POST "/v1/chat/completions"

First request succeeds (16s, HTTP 200), second fails after user interruption.

Verified Working

  • ✅ All Ollama API endpoints respond correctly (tested via Postman)
  • ✅ Both /v1/chat/completions (OpenAI-compatible) and /api/chat (native)
  • ✅ Streaming and non-streaming modes
  • ✅ Models generate text properly via native Ollama CLI

Analysis

The issue appears to be in OpenCode's response parsing/display logic, not the Ollama API itself. Ollama successfully processes requests, but OpenCode fails to handle the responses.

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 19, 2025
  2. lnicola commented on Nov 19, 2025

    @lnicola

    Can't reproduce (@ai-sdk/openai-compatible works fine for me), but I can confirm there's no error reporting whatsoever.

  3. rekram1-node commented on Nov 19, 2025

    @rekram1-node
    Collaborator

    @guglielmo maybe try:

    opencode run hello --print-logs

    and show us the output

  4. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 19, 2025
  5. lnicola commented on Nov 20, 2025

    @lnicola

    Actually, I take that back. I can chat, but doing anything that involves tools (like /init) seems to fail with gpt-oss:20b, while qwen3-coder:30b doesn't even respond with anything most of the time. There was a recent change in ollama regarding tool ids in calls, it might be related.

    I also tried the Zed assistant, it works with both models, even if it didn't seem great overall (but IDK).

  6. rekram1-node commented on Nov 20, 2025

    @rekram1-node
    Collaborator

    Whats ur ollama context size, prolly related to that by default it has 4k context or something so nothing will work

  7. lnicola commented on Nov 20, 2025

    @lnicola

    Oh, sorry, you're right. I actually increased it, but decreased it recently and forgot about it. gpt-oss:20b works now, while qwen3-coder:30b still doesn't show any output most of the time. It's slower, probably, but it was working "fine" in Zed, as I mentioned.

    I tried --print-logs, but by default I only get:

    INFO  2025-11-20T06:01:25 +130ms service=default version=1.0.80 args=["--print-logs"] opencode
    ERROR 2025-11-20T06:02:40 +75238ms service=acp-command promise={} reason=EditBuffer is destroyed Unhandled rejection
    ERROR 2025-11-20T06:02:40 +0ms service=default e=EditBuffer is destroyed rejection
    ERROR 2025-11-20T06:02:40 +0ms service=default Error: EditBuffer is destroyed
    

    EDIT: hmm, that's a lot of context.

  8. rekram1-node commented on Nov 20, 2025

    @rekram1-node
    Collaborator

    I think Zed uses the native ollama endpoints instead of openai compatible ones, those other ones support the client setting context stuff the openai compat ones dont

  9. guglielmo commented on Nov 20, 2025

    @guglielmo
    Author

    @rekram1-node

    @guglielmo maybe try:

    opencode run hello --print-logs

    and show us the output

    I am using a model derived from qwen2.5-coder:7b with this Modelfile:

    FROM qwen2.5-coder:7b
    
    PARAMETER num_ctx 32768
    

    I invoke opencode like this:

    > opencode run hello --print-logs --log-level DEBUG --model ollama/qwen2.5-coder:7b-32k
    INFO  2025-11-20T07:06:13 +510ms service=default version=1.0.80 args=["run","hello","--print-logs","--log-level","DEBUG","--model","ollama/qwen2.5-coder:7b-32k"] opencode
    INFO  2025-11-20T07:06:13 +2ms service=default directory=/home/gu/Workspace/ai-locally creating instance
    INFO  2025-11-20T07:06:13 +1ms service=project directory=/home/gu/Workspace/ai-locally fromDirectory
    INFO  2025-11-20T07:06:13 +17ms service=default directory=/home/gu/Workspace/ai-locally bootstrapping
    INFO  2025-11-20T07:06:13 +6ms service=config path=/home/gu/.config/opencode/config.json loading
    INFO  2025-11-20T07:06:13 +17ms service=config path=/home/gu/.config/opencode/opencode.json loading
    INFO  2025-11-20T07:06:13 +4ms service=config path=/home/gu/.config/opencode/opencode.jsonc loading
    INFO  2025-11-20T07:06:13 +8ms service=bun cmd=["/home/gu/.local/share/fnm/node-versions/v24.6.0/installation/lib/node_modules/opencode-ai/node_modules/opencode-linux-x64/bin/opencode","add","@opencode-ai/[email protected]","--exact"] cwd=/home/gu/.config/opencode running
    INFO  2025-11-20T07:06:13 +10ms service=bun code=0 stdout=bun add v1.3.2 (b131639c)
    
    installed @opencode-ai/[email protected]
    
    [4.00ms] done
     stderr=Saved lockfile
     done
    INFO  2025-11-20T07:06:13 +3ms service=plugin [email protected] loading plugin
    INFO  2025-11-20T07:06:13 +3ms service=plugin [email protected] loading plugin
    INFO  2025-11-20T07:06:13 +27ms service=bus type=* subscribing
    INFO  2025-11-20T07:06:13 +0ms service=bus type=session.updated subscribing
    INFO  2025-11-20T07:06:13 +1ms service=bus type=message.updated subscribing
    INFO  2025-11-20T07:06:13 +0ms service=bus type=message.part.updated subscribing
    INFO  2025-11-20T07:06:13 +0ms service=format init
    INFO  2025-11-20T07:06:13 +0ms service=bus type=file.edited subscribing
    INFO  2025-11-20T07:06:13 +0ms service=lsp serverIds=deno, typescript, vue, eslint, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, sourcekit-lsp, rust, clangd, svelte, astro, jdtls, yaml-ls, lua-ls, php intelephense enabled LSP servers
    INFO  2025-11-20T07:06:13 +2ms service=bus type=command.executed subscribing
    INFO  2025-11-20T07:06:14 +44ms service=server method=POST path=/session request
    INFO  2025-11-20T07:06:14 +1ms service=server status=started method=POST path=/session request
    INFO  2025-11-20T07:06:14 +4ms service=session id=ses_55fea3584ffeX6x7EJUV0t6Uba version=1.0.80 projectID=global directory=/home/gu/Workspace/ai-locally title=New session - 2025-11-20T07:06:14.011Z time={"created":1763622374012,"updated":1763622374012} created
    INFO  2025-11-20T07:06:14 +1ms service=bus type=session.created publishing
    INFO  2025-11-20T07:06:14 +0ms service=bus type=session.updated publishing
    INFO  2025-11-20T07:06:14 +2ms service=server status=completed duration=7 method=POST path=/session request
    INFO  2025-11-20T07:06:14 +5ms service=server method=GET path=/config request
    INFO  2025-11-20T07:06:14 +0ms service=server status=started method=GET path=/config request
    INFO  2025-11-20T07:06:14 +0ms service=server status=completed duration=0 method=GET path=/config request
    INFO  2025-11-20T07:06:14 +5ms service=server method=GET path=/event request
    INFO  2025-11-20T07:06:14 +0ms service=server status=started method=GET path=/event request
    INFO  2025-11-20T07:06:14 +0ms service=server event connected
    INFO  2025-11-20T07:06:14 +3ms service=bus type=* subscribing
    INFO  2025-11-20T07:06:14 +2ms service=server status=completed duration=5 method=GET path=/event request
    INFO  2025-11-20T07:06:14 +7ms service=server method=POST path=/session/ses_55fea3584ffeX6x7EJUV0t6Uba/message request
    INFO  2025-11-20T07:06:14 +0ms service=server status=started method=POST path=/session/ses_55fea3584ffeX6x7EJUV0t6Uba/message request
    INFO  2025-11-20T07:06:14 +5ms service=server status=completed duration=5 method=POST path=/session/ses_55fea3584ffeX6x7EJUV0t6Uba/message request
    INFO  2025-11-20T07:06:14 +10ms service=bus type=message.updated publishing
    INFO  2025-11-20T07:06:14 +2ms service=bus type=message.part.updated publishing
    INFO  2025-11-20T07:06:14 +2ms service=bus type=session.updated publishing
    INFO  2025-11-20T07:06:14 +3ms service=session.prompt step=0 sessionID=ses_55fea3584ffeX6x7EJUV0t6Uba loop
    INFO  2025-11-20T07:06:14 +11ms service=provider status=started state
    INFO  2025-11-20T07:06:14 +3ms service=models.dev file={} refreshing
    INFO  2025-11-20T07:06:14 +5ms service=provider init
    INFO  2025-11-20T07:06:14 +6ms service=provider providerID=openrouter found
    INFO  2025-11-20T07:06:14 +0ms service=provider providerID=opencode found
    INFO  2025-11-20T07:06:14 +0ms service=provider providerID=anthropic found
    INFO  2025-11-20T07:06:14 +0ms service=provider providerID=ollama found
    INFO  2025-11-20T07:06:14 +0ms service=provider status=completed duration=14 state
    INFO  2025-11-20T07:06:14 +0ms service=provider providerID=ollama modelID=qwen2.5-coder:7b-32k getModel
    INFO  2025-11-20T07:06:14 +1ms service=provider status=started providerID=ollama getSDK
    INFO  2025-11-20T07:06:14 +1ms service=provider providerID=ollama modelID=qwen2.5-coder:7b-32k getModel
    INFO  2025-11-20T07:06:14 +0ms service=provider status=started providerID=ollama getSDK
    INFO  2025-11-20T07:06:14 +109ms service=provider status=completed duration=110 providerID=ollama getSDK
    INFO  2025-11-20T07:06:14 +2ms service=provider providerID=ollama modelID=qwen2.5-coder:7b-32k found
    INFO  2025-11-20T07:06:14 +3ms service=bus type=message.updated publishing
    INFO  2025-11-20T07:06:14 +2ms service=provider status=completed duration=116 providerID=ollama getSDK
    INFO  2025-11-20T07:06:14 +1ms service=provider providerID=ollama modelID=qwen2.5-coder:7b-32k found
    INFO  2025-11-20T07:06:14 +34ms service=session.processor process
    INFO  2025-11-20T07:06:14 +7ms service=bus type=session.status publishing
    INFO  2025-11-20T07:06:14 +15ms service=bus type=message.updated publishing
    INFO  2025-11-20T07:06:14 +1ms service=bus type=session.updated publishing
    INFO  2025-11-20T07:06:14 +1ms service=bus type=session.diff publishing

    The logs of ollama serve running in another terminal tab shows nothing.

    After about 2 minutes I CTRL+C the opencode command and I get these logs in the ollama logs:

    time=2025-11-20T08:09:01.353+01:00 level=INFO source=server.go:1433 msg="aborting completion request due to client closing the connection"
    [GIN] 2025/11/20 - 08:09:01 | 500 |         2m47s |       127.0.0.1 | POST     "/v1/chat/completions"
    time=2025-11-20T08:09:01.353+01:00 level=INFO source=runner.go:634 msg="aborting completion request due to client closing the connection"
    [GIN] 2025/11/20 - 08:09:01 | 500 |         2m47s |       127.0.0.1 | POST     "/v1/chat/completions"
    
  10. guglielmo commented on Nov 20, 2025

    @guglielmo
    Author

    Ok, I think I get the problem. It's just slow.
    opencode is probably adding a ton of system prompt as context, and I am on a CPU, so, it takes long to generate a response.
    I switched to gpt-oss model (I think that's irrelevant, though, with qwen2.5-coder:7b-32k it took almost 30 minutes) with

    opencode run "what is the capital of France?" --print-logs --log-level DEBUG --model ollama/gpt-oss
    

    and it took 7 minutes to get the answer, during which ollama logged this:

    nov 20 09:20:22 thinkpadx1 ollama[1204759]: [GIN] 2025/11/20 - 09:20:22 | 200 |  20.14332306s |       127.0.0.1 | POST     "/v1/chat/completions"
    nov 20 09:20:22 thinkpadx1 ollama[1204759]: time=2025-11-20T09:20:22.491+01:00 level=WARN source=runner.go:186 msg="truncating input prompt" limit=4096 prompt=8797 keep=4 new=4096
    nov 20 09:27:01 thinkpadx1 ollama[1204759]: [GIN] 2025/11/20 - 09:27:01 | 200 |         6m59s |       127.0.0.1 | POST     "/v1/chat/completions"
    

    and this

    nov 20 09:20:22 thinkpadx1 ollama[1204759]: time=2025-11-20T09:20:22.491+01:00 level=WARN source=runner.go:186 msg="truncating input prompt" limit=4096 prompt=8797 keep=4 new=4096
    

    seems to be revealing that the prompt being sent is around 9k tokens, even to know the capital of France ... and it's being truncated notwithstanding the 32k of context the model has (must be an ollama setting).

    The relevant thing appears to be that in my configuration (CPU, 32GB of RAM) it is impossible to use local llms with large contexts. Thus using opencode (or Zen, for that matter, which gives me pretty similar results), is virtually impossible.

    I'd close the issue, as this seems not to be fully relevant for the opencode repo.

  11. rekram1-node commented on Nov 20, 2025

    @rekram1-node
    Collaborator

    opencode is probably adding a ton of system prompt as context

    It's because of tools primarily, they slow local models down a lot

  12. added a commit that references this issue on Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions