Skip to content

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

Closed

Description

@filaupe

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

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 14, 2025
  2. rekram1-node commented on Nov 14, 2025

    @rekram1-node
    Collaborator

    @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

  3. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 14, 2025
  4. self-assigned this
    on Nov 14, 2025
  5. filaupe commented on Nov 14, 2025

    @filaupe
    Author

    @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)
    
  6. rekram1-node commented on Nov 14, 2025

    @rekram1-node
    Collaborator

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

    If u show ur config I can help you through it

  7. filaupe commented on Nov 14, 2025

    @filaupe
    Author

    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
    }
    }

  8. rekram1-node commented on Nov 15, 2025

    @rekram1-node
    Collaborator

    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^

  9. filaupe commented on Nov 16, 2025

    @filaupe
    Author

    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.

  10. rekram1-node commented on Nov 16, 2025

    @rekram1-node
    Collaborator

    Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions