App is calling the wrong endpoint for the Ollama provider when using local models #2873

Closed
opened 2026-02-16 17:37:37 -05:00 by yindo · 7 comments
Owner

Originally created by @filaupe on GitHub (Nov 14, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

I discovered that the application is using the wrong endpoint when sending requests to the Ollama provider for local models.
Currently, OpenCode is calling:

/chat/completions

However, the correct endpoint for the Ollama chat API is:

/chat

This causes messages to not be processed correctly by the local Ollama models.
The implementation needs to be updated so that the provider uses the /chat endpoint as defined in the official Ollama documentation.

OpenCode version

v1.0.65

Steps to reproduce

services:
local-llm:
image: ollama/ollama
container_name: local-llm
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
healthcheck:
test: ["CMD-SHELL", "ollama ls >/dev/null 2>&1 || exit 1"]
interval: 10s
timeout: 5s
retries: 60
start_period: 20s
restart: unless-stopped

ollama-puller:
image: alpine:latest
container_name: ollama-puller
depends_on:
local-llm:
condition: service_healthy
volumes:
- "./pull-models.sh:/pull-models.sh"
environment:
MODELS: "gemma3:4b embeddinggemma:latest"
entrypoint: ["/bin/sh", "/pull-models.sh"]
healthcheck:
test: ["CMD-SHELL", "test -f /tmp/models_ready"]
interval: 30s
timeout: 10s
retries: 600
start_period: 60s
restart: unless-stopped

ai-cli:
image: node:22-bookworm
container_name: ai-cli
tty: true
stdin_open: true
ports:
- "4096:4096"
volumes:
- "C:\Users\...\Documents\GitHub\...\...\environment:/environment"
environment:
OPENCODE_CONFIG: "/environment/custom-config.json"
depends_on:
local-llm:
condition: service_healthy
ollama-puller:
condition: service_healthy
working_dir: /environment/workspace
command: >
bash -lc '
npm install -g npm@latest &&
npm install -g opencode-ai@latest &&
opencode serve --hostname 0.0.0.0 --port 4096
'
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4096/app || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped

volumes:
ollama_data:

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @filaupe on GitHub (Nov 14, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description I discovered that the application is using the wrong endpoint when sending requests to the Ollama provider for local models. Currently, OpenCode is calling: ``` /chat/completions ``` However, the correct endpoint for the Ollama chat API is: ``` /chat ``` This causes messages to not be processed correctly by the local Ollama models. The implementation needs to be updated so that the provider uses the `/chat` endpoint as defined in the official Ollama documentation. ### OpenCode version v1.0.65 ### Steps to reproduce services: local-llm: image: ollama/ollama container_name: local-llm ports: - "11434:11434" volumes: - ollama_data:/root/.ollama healthcheck: test: ["CMD-SHELL", "ollama ls >/dev/null 2>&1 || exit 1"] interval: 10s timeout: 5s retries: 60 start_period: 20s restart: unless-stopped ollama-puller: image: alpine:latest container_name: ollama-puller depends_on: local-llm: condition: service_healthy volumes: - "./pull-models.sh:/pull-models.sh" environment: MODELS: "gemma3:4b embeddinggemma:latest" entrypoint: ["/bin/sh", "/pull-models.sh"] healthcheck: test: ["CMD-SHELL", "test -f /tmp/models_ready"] interval: 30s timeout: 10s retries: 600 start_period: 60s restart: unless-stopped ai-cli: image: node:22-bookworm container_name: ai-cli tty: true stdin_open: true ports: - "4096:4096" volumes: - "C:\\Users\\...\\Documents\\GitHub\\...\\...\\environment:/environment" environment: OPENCODE_CONFIG: "/environment/custom-config.json" depends_on: local-llm: condition: service_healthy ollama-puller: condition: service_healthy working_dir: /environment/workspace command: > bash -lc ' npm install -g npm@latest && npm install -g opencode-ai@latest && opencode serve --hostname 0.0.0.0 --port 4096 ' healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:4096/app || exit 1"] interval: 10s timeout: 5s retries: 5 start_period: 30s restart: unless-stopped volumes: ollama_data: ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:37:37 -05:00
yindo closed this issue 2026-02-16 17:37:37 -05:00
Author
Owner

@rekram1-node commented on GitHub (Nov 14, 2025):

@filaupe can you show me your opencode config? If you are using the openai compatible provider then it will use the openai compatible endpoint because /chat isn't compatible

@rekram1-node commented on GitHub (Nov 14, 2025): @filaupe can you show me your opencode config? If you are using the openai compatible provider then it will use the openai compatible endpoint because /chat isn't compatible
Author
Owner

@filaupe commented on GitHub (Nov 14, 2025):

@filaupe can you show me your opencode config? If you are using the openai compatible provider then it will use the openai compatible endpoint because /chat isn't compatible

Apparently that was it, but what would be the correct config? After I removed that line, it started returning an error.

|opencode server listening on http://0.0.0.0:4096⁠

507 | ...options,

508 | })

509 | s.sdk.set(key, loaded)

510 | return loaded as SDK

511 | })().catch((e) => {

512 | throw new InitError({ providerID: provider.id }, { cause: e })

              ^

ProviderInitError: ProviderInitError

data: {

providerID: "ollama",

},

  at <anonymous> (src/provider/provider.ts:512:13)

500 | timeout: false,

501 | })

502 | }

503 | }

504 | const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]

505 | const loaded = fn({

                       ^

TypeError: fn2 is not a function. (In 'fn2({

      name: provider.id,

      ...options2

    })', 'fn2' is undefined)

  at <anonymous> (src/provider/provider.ts:505:22)
@filaupe commented on GitHub (Nov 14, 2025): > [@filaupe](https://github.com/filaupe) can you show me your opencode config? If you are using the openai compatible provider then it will use the openai compatible endpoint because /chat isn't compatible Apparently that was it, but what would be the correct config? After I removed that line, it started returning an error. |opencode server listening on [http://0.0.0.0:4096⁠](http://0.0.0.0:4096/) 507 | ...options, 508 | }) 509 | s.sdk.set(key, loaded) 510 | return loaded as SDK 511 | })().catch((e) => { 512 | throw new InitError({ providerID: provider.id }, { cause: e }) ^ ProviderInitError: ProviderInitError data: { providerID: "ollama", }, at <anonymous> (src/provider/provider.ts:512:13) 500 | timeout: false, 501 | }) 502 | } 503 | } 504 | const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!] 505 | const loaded = fn({ ^ TypeError: fn2 is not a function. (In 'fn2({ name: provider.id, ...options2 })', 'fn2' is undefined) at <anonymous> (src/provider/provider.ts:505:22)
Author
Owner

@rekram1-node commented on GitHub (Nov 14, 2025):

Maybe try replacing the npm package with ollama-ai-provider-v2

If u show ur config I can help you through it

@rekram1-node commented on GitHub (Nov 14, 2025): Maybe try replacing the `npm` package with `ollama-ai-provider-v2` If u show ur config I can help you through it
Author
Owner

@filaupe commented on GitHub (Nov 14, 2025):

Maybe try replacing the npm package with ollama-ai-provider-v2

If u show ur config I can help you through it

Ok:

{
"$schema": "https://opencode.ai/config.json",
"agent": {
"build": {
"mode": "primary",
"disable": false,
"model": "ollama/gemma3:4b",
"prompt": "{file:./prompts/build.txt}",
"description": "Builds code for best practices and potential issues"
},
"code-review": {
"mode": "subagent",
"disable": false,
"model": "ollama/gemma3:4b",
"prompt": "{file:./prompts/code-review.txt}",
"description": "Reviews code for best practices and potential issues"
}
},
"disabled_providers": ["opencode"],
"provider": {
"ollama": {
"name": "Ollama (local)",
"options": {
"baseURL": "http://local-llm:11434"
},
"models": {
"gemma3:4b": {
"name": "gemma3:4b"
}
}
}
},
"tools": {
"write": true,
"edit": true,
"read": true,
"bash": true,
"list": true,
"grep": true,
"patch": true,
"glob": true,
"todowrite": true,
"todoread": true,
"webfetch": true
}
}

@filaupe commented on GitHub (Nov 14, 2025): > Maybe try replacing the `npm` package with `ollama-ai-provider-v2` > > If u show ur config I can help you through it Ok: { "$schema": "https://opencode.ai/config.json", "agent": { "build": { "mode": "primary", "disable": false, "model": "ollama/gemma3:4b", "prompt": "{file:./prompts/build.txt}", "description": "Builds code for best practices and potential issues" }, "code-review": { "mode": "subagent", "disable": false, "model": "ollama/gemma3:4b", "prompt": "{file:./prompts/code-review.txt}", "description": "Reviews code for best practices and potential issues" } }, "disabled_providers": ["opencode"], "provider": { "ollama": { "name": "Ollama (local)", "options": { "baseURL": "http://local-llm:11434" }, "models": { "gemma3:4b": { "name": "gemma3:4b" } } } }, "tools": { "write": true, "edit": true, "read": true, "bash": true, "list": true, "grep": true, "patch": true, "glob": true, "todowrite": true, "todoread": true, "webfetch": true } }
Author
Owner

@rekram1-node commented on GitHub (Nov 14, 2025):

And this one causes that issue right:

  "provider": {
    "ollama": {
      "name": "Ollama (local)",
      "npm": "ollama-ai-provider-v2"
      "options": {
        "baseURL": "http://local-llm:11434"
      },
      "models": {
        "gemma3:4b": {
          "name": "gemma3:4b"
        }
      }
    }
  },

Hm is there any reason you can't use the openai compatible one? I think a patch needs to be made to this ollama provider to work for your usecase if this is breaking^

@rekram1-node commented on GitHub (Nov 14, 2025): And this one causes that issue right: ``` "provider": { "ollama": { "name": "Ollama (local)", "npm": "ollama-ai-provider-v2" "options": { "baseURL": "http://local-llm:11434" }, "models": { "gemma3:4b": { "name": "gemma3:4b" } } } }, ``` Hm is there any reason you can't use the openai compatible one? I think a patch needs to be made to this ollama provider to work for your usecase if this is breaking^
Author
Owner

@filaupe commented on GitHub (Nov 16, 2025):

And this one causes that issue right:

  "provider": {
    "ollama": {
      "name": "Ollama (local)",
      "npm": "ollama-ai-provider-v2"
      "options": {
        "baseURL": "http://local-llm:11434"
      },
      "models": {
        "gemma3:4b": {
          "name": "gemma3:4b"
        }
      }
    }
  },

Hm is there any reason you can't use the openai compatible one? I think a patch needs to be made to this ollama provider to work for your usecase if this is breaking^

Here is the text in English:

I was able to fix the issue. The solution was to keep using "npm": "@ai-sdk/openai-compatible", but update the Ollama baseURL to "http://ollama-server:11434/v1". After that, everything worked correctly.

@filaupe commented on GitHub (Nov 16, 2025): > And this one causes that issue right: > > ``` > "provider": { > "ollama": { > "name": "Ollama (local)", > "npm": "ollama-ai-provider-v2" > "options": { > "baseURL": "http://local-llm:11434" > }, > "models": { > "gemma3:4b": { > "name": "gemma3:4b" > } > } > } > }, > ``` > > Hm is there any reason you can't use the openai compatible one? I think a patch needs to be made to this ollama provider to work for your usecase if this is breaking^ Here is the text in English: I was able to fix the issue. The solution was to keep using `"npm": "@ai-sdk/openai-compatible"`, but update the Ollama `baseURL` to `"http://ollama-server:11434/v1"`. After that, everything worked correctly.
Author
Owner

@rekram1-node commented on GitHub (Nov 16, 2025):

Awesome

@rekram1-node commented on GitHub (Nov 16, 2025): Awesome
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2873