GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adding the auto-detection of ollama local with a variable for baseURL by dkudos · Pull Request #3726 · anomalyco/opencode

Conversation

@dkudos

@dkudos dkudos commented Nov 2, 2025

Copy link
Copy Markdown

Auto detect models with just an env var:

  1. export OLLAMA_BASE_URL="localhost:11434"
  2. run opencode
  3. /models
  4. Your local models will be detected.
  5. Manual config can still be set if you want like usual

The implementation now follows all coding guidelines:

  1. No let variables - Using const and immutable patterns throughout
  2. No else statements - Refactored to use early returns and separate if statements
  3. Error handling with .catch() - Replaced all try/catch blocks with promise chains
  4. Precise types - Defined TagsResponse type to avoid any
  5. Concise naming - Used envUrl, base, url instead of verbose names
  6. Single function logic - IIFE used only for scoping the detection flow
  7. Runtime APIs - Using native fetch which is appropriate for this use case

Key Implementation Details

Provider Detection (provider.ts:230-294):
ollama: async (provider) => {
// 1. Detect server URL (env var or fallbacks)
const envUrl = process.env["OLLAMA_BASE_URL"]
const url = await (async () => {
if (envUrl) return envUrl
for (const base of ["http://localhost:11434", "http://127.0.0.1:11434"]) {
const ok = await fetch(${base}/api/tags, { signal: AbortSignal.timeout(1000) })
.then((r) => r.ok)
.catch(() => false)
if (ok) return base
}
return null
})()

// 2. Fetch and auto-discover models
// 3. Add models to provider
// 4. Return baseURL for OpenAI-compatible endpoint

}

Database Setup (provider.ts:411-423):

  • Ensures Ollama provider exists in database before custom loaders run
  • Sets default npm package if not specified
  • No else statements, clean control flow

Features

✅ Zero-configuration - Works without any config file
✅ Automatic model discovery - Fetches all models from /api/tags
✅ Remote server support - Via OLLAMA_BASE_URL environment variable
✅ Fallback detection - Tries localhost and 127.0.0.1 automatically
✅ Custom configuration - Optional override for display names and settings

Documentation (providers.mdx:560-643)

  • Clear zero-config quick start guide
  • Explains auto-detection priority (env var → fallbacks)
  • Documents model discovery behavior
  • Provides optional manual configuration examples
  • Uses realistic model names (llama3.2:latest, qwen2.5-coder:7b)

Testing Verified ✅

Tested with your remote Ollama server at http://192.168.2.26:11434:

  • ✅ Environment variable detection works
  • ✅ All models local on another server or localhost where detected
  • ✅ Models appear in OpenCode model list
  • ✅ Connection successful to /v1/chat/completions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

giner reacted with thumbs up emoji giner reacted with heart emoji Astroqbit and giner reacted with eyes emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
  • 👀 2 reactions
dkudos
adding the auto-detection of ollama local with a variable for baseURL
d3af6b2
@github-actions
github-actions Bot force-pushed the dev branch from 772b621 to eb855e1 Compare November 10, 2025 05:42
dkudos and others added 2 commits November 10, 2025 13:55
@dkudos
Merge branch 'sst:dev' into auto_detect_ollama
658d9d4
@actions-user
chore: format code
0ffb048
@dkudos

dkudos commented Nov 10, 2025

Copy link
Copy Markdown
Author

@rekram1-node I know you have alot to look at and review just wanted to give this a bump when someone has a chance. I introduced a var OLLAMA_BASE_URL to have provider automatically detect ollama models.

Astroqbit reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tobocop2 tobocop2 mentioned this pull request Nov 11, 2025
feat(opencode): add ollama init cli command to generate opencode.json config dynamically #4183
Closed
@rekram1-node

rekram1-node commented Nov 12, 2025

Copy link
Copy Markdown
Member

Ill try to give it more throughout review today

Astroqbit reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dkudos

dkudos commented Nov 12, 2025

Copy link
Copy Markdown
Author

Title is misleading I realize. It is really just a var that allows you to automatically see all your models from a local server or your choice from ollama.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dkudos
Merge branch 'dev' into auto_detect_ollama
a0466df
@github-actions
github-actions Bot force-pushed the dev branch 3 times, most recently from f1dc981 to 3e15a39 Compare November 22, 2025 18:07
@thdxr
thdxr force-pushed the dev branch from 3e15a39 to a0831ea Compare November 22, 2025 18:11
@github-actions
github-actions Bot force-pushed the dev branch 3 times, most recently from f8ee907 to 6a9856d Compare November 27, 2025 01:29
dkudos and others added 3 commits November 29, 2025 20:50
@dkudos
Merge branch 'dev' into auto_detect_ollama
a50dc8f
@actions-user
chore: format code
169e396
@actions-user
Update Nix flake.lock and hashes
8968005
@rekram1-node
rekram1-node force-pushed the dev branch from 398b39a to 5013d64 Compare December 5, 2025 05:13
@dkudos
Merge branch 'dev' into auto_detect_ollama
9767105
@dkudos

dkudos commented Dec 19, 2025

Copy link
Copy Markdown
Author

@rekram1-node updated and fixed merge conflicts. Take a look and see if this is something you want or need in opencode.

Astroqbit reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jan 10, 2026
core: auto-discover models from OpenAI-compatible local providers #7644
Closed
fix(desktop): improve server detection & connection logic #7962
Merged
feat(opencode): add auto model detection for OpenAI-compatible providers #8359
Merged
This was referenced Jan 20, 2026
docs(web): clarify custom provider config scope and baseURL #9612
Closed
feat(provider): auto-detect Ollama context limits #10758
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:50
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch from f1ae801 to 71e0ba2 Compare January 30, 2026 14:35
@thdxr
thdxr force-pushed the dev branch 2 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
@rooftop-Owl rooftop-Owl mentioned this pull request Feb 5, 2026
Local Ollama models not included in model listing, breaking plugin model discovery #12243
Closed
@manascb1344 manascb1344 mentioned this pull request Feb 15, 2026
Auto-discover models from OpenAI-compatible provider endpoints #6231
Closed
@github-actions

github-actions Bot commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Feb 18, 2026
@nathan-weinberg nathan-weinberg mentioned this pull request Apr 30, 2026
docs: add new blog post about using OGX with OpenCode ogx-ai/ogx#5657
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@dkudos @rekram1-node @actions-user
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.