opencode icon indicating copy to clipboard operation
opencode copied to clipboard

How to configure a local large model

Open Khanviph opened this issue 5 months ago β€’ 14 comments

How to configure a local large model 1.I use Ollama 2.Model gpt-oss:120b

Khanviph avatar Aug 07 '25 08:08 Khanviph

Something like this, adjust for gpt based model:

https://opencode.ai/docs/providers/#ollama

{ "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "qwen3-coder:30b": { "name": "Qwen3-Coder 30B (MoE 3.3B active)" } } } }, "model": "ollama/qwen3-coder:30b" }

tommyboylab avatar Aug 07 '25 09:08 tommyboylab

Thank you @tommyboylab !

Ive tested it with your json and just changed the model definitions to the new gpt-oss variants and it works - not good in terms of model capability - but the communication to ollama works.

Here is how I achieved it:

  1. Installed ollama and opencode
  2. Started ollama (ollama start) and pulled the gpt-oss 20b model (ollama run gpt-oss:20b).
  3. Created a the opencode.jsonconfig file in my project folder with:
{
    "$schema": "https://opencode.ai/config.json",
    "provider": {
        "ollama": {
            "npm": "@ai-sdk/openai-compatible",
            "name": "Ollama (local)",
            "options": {
                "baseURL": "http://localhost:11434/v1"
            },
            "models": {
                "gpt-oss:20b": {
                    "name": "gpt-oss 20b local"
                }
            }
        }
    },
    "model": "ollama/gpt-oss:20b"
}
  1. Start opencode in the project directory.

I would recommend for testing to leave the terminal with the ollama start open to see the logs. There you can see if your model gets used by opencode and if its working at the moment.

Happy coding πŸ‘¨β€πŸ’»

Tr33Bug avatar Aug 07 '25 10:08 Tr33Bug

βœ… Auto-generate opencode.json for Ollama (via Bash)

This script allows you to automatically create a valid opencode.json configuration for [OpenCode](https://opencode.ai), based on the models currently available in your local [Ollama](https://ollama.com) instance.

🧠 What it does

  • Connects to your local Ollama server (IP or localhost)
  • Retrieves available model names via API
  • Lets you select a model using fzf
  • Writes a proper opencode.json file in the required format

πŸ“œ The Bash Script

#!/bin/bash

# OLLAMA Host/IP (adjust if needed)
OLLAMA_HOST="http://localhost:11434"

# Get list of available models
MODELS=$(curl -s "$OLLAMA_HOST/api/tags" | jq -r '.models[].name')

# Select model using fuzzy finder (fzf)
SELECTED=$(echo "$MODELS" | fzf --prompt="Choose a model > ")

# Exit if no model is selected
if [ -z "$SELECTED" ]; then
  echo "❌ No model selected – aborting."
  exit 1
fi

# Write opencode.json
cat > opencode.json <<EOF
{
  "\$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "$OLLAMA_HOST/v1"
      },
      "models": {
        "$SELECTED": {
          "name": "$SELECTED"
        }
      }
    }
  },
  "model": "ollama/$SELECTED"
}
EOF

echo "βœ… opencode.json created with model: $SELECTED"

βš™οΈ Requirements

Make sure the following tools are installed:


πŸ§ͺ How to use

  1. Save the script as generate-opencode.sh

  2. Make it executable:

    chmod +x generate-opencode.sh
    
  3. Run it:

    ./generate-opencode.sh
    

After running, you'll have a valid opencode.json that points to the exact Ollama model you selected.

You can now launch OpenCode and it will use that model directly.


🧩 Example opencode.json Output

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "llama3:8b": {
          "name": "llama3:8b"
        }
      }
    }
  },
  "model": "ollama/llama3:8b"
}

Gaetner84 avatar Aug 07 '25 16:08 Gaetner84

don't use ollama use LM studio

thdxr avatar Aug 07 '25 21:08 thdxr

no i use ollama it is better on server and works perfect!

Gaetner84 avatar Aug 08 '25 16:08 Gaetner84

This clearly works, so probably just close the issue?

Any suggestions on how to get opencode to work better with local models? I've only ever had good performance using opencode with Anthropic models

chbornman avatar Aug 08 '25 18:08 chbornman

don't use ollama use LM studio

Why tho

nathfavour avatar Aug 20 '25 10:08 nathfavour

LM studio seems much more reliable, I consistently see people having ollama issues because they arent handling certain models correctly, like they had some issue with qwen models (or some other one) were they didnt parse out tool calls properly and it was an issue for a while…

rekram1-node avatar Aug 20 '25 12:08 rekram1-node

if i have a webui as frontend to ollama. My gpt-oss keeps returning "max_tokens must be at least 1, got -1928." even though I can connect it with my zed or even via cli.

vpereira avatar Nov 30 '25 16:11 vpereira

@vpereira can you send me output of: opencode debug config

rekram1-node avatar Dec 02 '25 17:12 rekram1-node

@vpereira can you send me output of: opencode debug config

sure, here it is:

➜ opencode debug config
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openwebui/qwen3-coder:30b",
  "provider": {
    "openwebui": {
      "name": "Remote DeepSeek Coder",
      "npm": "@ai-sdk/openai-compatible",
      "models": {
        "deepseek-coder-v2:16b": {
          "name": "deepseek-coder-v2:16b (remote)",
          "limit": {
            "context": 32000,
            "output": 4000
          }
        },
        "gpt-oss": {
          "name": "gpt-oss",
          "limit": {
            "context": 8192,
            "output": 1024
          }
        },
        "qwen3-coder:30b": {
          "name": "qwen3-coder:30b"
        }
      },
      "options": {
        "baseURL": "https://ollama.myhome.xyz/api"
      }
    }
  },
  "agent": {},
  "mode": {},
  "plugin": [],
  "command": {},
  "username": "kimura",
  "keybinds": {
    "leader": "ctrl+x",
    "app_exit": "ctrl+c,ctrl+d,<leader>q",
    "editor_open": "<leader>e",
    "theme_list": "<leader>t",
    "sidebar_toggle": "<leader>b",
    "status_view": "<leader>s",
    "session_export": "<leader>x",
    "session_new": "<leader>n",
    "session_list": "<leader>l",
    "session_timeline": "<leader>g",
    "session_share": "none",
    "session_unshare": "none",
    "session_interrupt": "escape",
    "session_compact": "<leader>c",
    "messages_page_up": "pageup",
    "messages_page_down": "pagedown",
    "messages_half_page_up": "ctrl+alt+u",
    "messages_half_page_down": "ctrl+alt+d",
    "messages_first": "ctrl+g,home",
    "messages_last": "ctrl+alt+g,end",
    "messages_copy": "<leader>y",
    "messages_undo": "<leader>u",
    "messages_redo": "<leader>r",
    "messages_toggle_conceal": "<leader>h",
    "model_list": "<leader>m",
    "model_cycle_recent": "f2",
    "model_cycle_recent_reverse": "shift+f2",
    "command_list": "ctrl+p",
    "agent_list": "<leader>a",
    "agent_cycle": "tab",
    "agent_cycle_reverse": "shift+tab",
    "input_clear": "ctrl+c",
    "input_forward_delete": "ctrl+d",
    "input_paste": "ctrl+v",
    "input_submit": "return",
    "input_newline": "shift+return,ctrl+j",
    "history_previous": "up",
    "history_next": "down",
    "session_child_cycle": "<leader>right",
    "session_child_cycle_reverse": "<leader>left",
    "terminal_suspend": "ctrl+z"
  }
}

vpereira avatar Dec 04 '25 15:12 vpereira

@vpereira im guessing u had the error w/ qwen3-coder:30b? I think that's because there is no limit set there

rekram1-node avatar Dec 04 '25 21:12 rekram1-node

@vpereira im guessing u had the error w/ qwen3-coder:30b? I think that's because there is no limit set there

Hi @rekram1-node

No unfortunately, i get the following error:

My Prompt was: "Please analyse my code base"

I'll help you analyze your codebase. To do this properly, I'll need to explore your project structure and files. Let me start by examining what files and directories you have.
βš™ invalid [tool=todolist, error=Model tried to call unavailable tool 'todolist'. Available tools: invalid, bash, read, glob, grep, list, edit, write, task, webfetch, todowrite, todoread.]

vpereira avatar Dec 05 '25 15:12 vpereira

im guessing u had the error w/ qwen3-coder:30b? I think that's because there is no limit set there

with the model gpt-oss, i get the error "max_tokens must be at least 1, got -2490."

OpenCode version 1.0.133

With aider I am able to use the model and interact with my file system

vpereira avatar Dec 05 '25 15:12 vpereira