How to configure a local large model
How to configure a local large model 1.I use Ollama 2.Model gpt-oss:120b
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" }
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:
- Installed ollama and opencode
- Started ollama (
ollama start) and pulled the gpt-oss 20b model (ollama run gpt-oss:20b). - 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"
}
- Start
opencodein 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 π¨βπ»
β
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.jsonfile 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:
[jq](https://stedolan.github.io/jq/)β for JSON parsing[fzf](https://github.com/junegunn/fzf)β for model selectioncurl,bash- Ollama running (
ollama start)
π§ͺ How to use
-
Save the script as
generate-opencode.sh -
Make it executable:
chmod +x generate-opencode.sh -
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"
}
don't use ollama use LM studio
no i use ollama it is better on server and works perfect!
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
don't use ollama use LM studio
Why tho
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β¦
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 can you send me output of: opencode debug config
@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 im guessing u had the error w/ qwen3-coder:30b? I think that's because there is no limit set there
@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.]
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