Skip to content

need help setting up ollama #4862

Closed
Closed

Description

@YeetDogman

OpenCode Version: 1.0.119
Operating System: Linux

Problem Description:
OpenCode fails to initialize the Ollama provider when attempting to run a command, resulting in a ProviderInitError with a TypeError: fn2 is not a function. The Ollama server is running, models are
available, and OpenCode correctly lists the Ollama models when opencode models is executed.

Steps to Reproduce:

  1. Ensure Ollama is installed and running (ollama serve).
  2. Pull the desired Ollama model, e.g., llama3.1:8b (ollama pull llama3.1:8b).
  3. Ensure the OpenCode configuration file exists at /home/liam/.config/opencode/opencode.json with the following content:

1 {"$schema":"https://opencode.ai/config.json","provider":{"ollama":{"options":{"baseURL":"http://localhost:11434/v1"},"models":{"llama3.1:8b":{},"qwen2.5-coder:14b":{},"mistral:7b":{},
"deepseek-coder-v2:16b-lite-instruct-q5_K_M":{}}}},"model":"ollama/llama3.1:8b","mcp":{"MCP_DOCKER":{"type":"local","command":["docker","mcp","gateway","run"],"enabled":true}}}
4. Verify that OpenCode recognizes Ollama models by running: /home/liam/.opencode/bin/opencode models
(Expected: Ollama models are listed).
5. Attempt to run OpenCode with an Ollama model: /home/liam/.opencode/bin/opencode run "test message" --print-logs

Expected Behavior:
OpenCode should successfully use the configured Ollama model to generate a response.

Actual Behavior:
The command fails with the following error:

1 INFO  2025-11-28T10:57:00 +0ms service=provider providerID=ollama modelID=llama3.1:8b getModel
2 INFO  2025-11-28T10:57:00 +0ms service=provider status=started providerID=ollama getSDK
3 ...
4 605 |         ...options,
5 606 |       })
6 607 |       s.sdk.set(key, loaded)
7 608 |       return loaded as SDK
8 609 |     })().catch((e) => {
9 610 |       throw new InitError({ providerID: provider.id }, { cause: e })

10 ^
11 ProviderInitError: ProviderInitError
12 data: {
13 providerID: "ollama",
14 },
15
16 at (src/provider/provider.ts:610:13)
17
18 598 | }
19 599 |
20 600 | const mod = await import(installedPath)
21 601 |
22 602 | const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
23 603 | const loaded = fn({
24 ^
25 TypeError: fn2 is not a function. (In 'fn2({
26 name: provider.id,
27 ...options2
28 })', 'fn2' is undefined)
29 at (src/provider/provider.ts:603:22)

Activity

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

    @rekram1-node
    Contributor

    @YeetDogman did you see this:
    https://opencode.ai/docs/providers/#ollama

    I think you need to update your config to be:

    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "ollama": {
          "npm": "@ai-sdk/openai-compatible", // <<< THIS RIGHT HERE
          "options": {
            "baseURL": "http://localhost:11434/v1"
          },
          "models": {
            "llama3.1:8b": {},
            "qwen2.5-coder:14b": {},
            "mistral:7b": {},
            "deepseek-coder-v2:16b-lite-instruct-q5_K_M": {}
          }
        }
      },
      "model": "ollama/llama3.1:8b",
      "mcp": {
        "MCP_DOCKER": {
          "type": "local",
          "command": [
            "docker",
            "mcp",
            "gateway",
            "run"
          ],
          "enabled": true
        }
      }
    }
    
  3. self-assigned this
    on Nov 28, 2025
  4. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 28, 2025
  5. changed the title [-]Issue Title: ProviderInitError with TypeError: fn2 is not a function when using Ollama[/-] [+]need help setting up ollama[/+] on Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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