need help setting up ollama #3184

Closed
opened 2026-02-16 17:39:02 -05:00 by yindo · 1 comment
Owner

Originally created by @YeetDogman on GitHub (Nov 28, 2025).

Originally assigned to: @rekram1-node on GitHub.

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)

Originally created by @YeetDogman on GitHub (Nov 28, 2025). Originally assigned to: @rekram1-node on GitHub. 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 <anonymous> (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 <anonymous> (src/provider/provider.ts:603:22)
yindo closed this issue 2026-02-16 17:39:02 -05:00
Author
Owner

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

@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
    }
  }
}
@rekram1-node commented on GitHub (Nov 28, 2025): @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 } } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3184