fix: make Ollama base URL configurable via OLLAMA_BASE_URL env var - #309
Closed
arnavgoel17 wants to merge 2 commits into
Closed
fix: make Ollama base URL configurable via OLLAMA_BASE_URL env var#309arnavgoel17 wants to merge 2 commits into
arnavgoel17 wants to merge 2 commits into
Conversation
Hardcoded 'http://localhost:11434' prevented deployed instances from
reaching a user's local Ollama. The server resolves localhost to itself,
not the client's machine.
Changes:
- config.py: add OLLAMA_BASE_URL = os.getenv('OLLAMA_BASE_URL', 'http://localhost:11434')
- ollama_services.py: use Config.OLLAMA_BASE_URL instead of hardcoded string
- chat_routes.py: use Config.OLLAMA_BASE_URL for both /api/generate calls
- .env.example: document OLLAMA_BASE_URL with usage example
Closes Rucha-Ambaliya#291
|
@arnavgoel17 is attempting to deploy a commit to the Rucha Ambaliya's projects Team on Vercel. A member of the Team first needs to authorize it. |
1 task
Owner
|
Follow the pr template please |
Author
Could you please elaborate a lil? I'm new to this repo. |
Owner
|
Also please attach a video of testing, and/or a guide on how to test it |
Author
|
Heyy @Rucha-Ambaliya, I have edited the pr template as described. |
Owner
Recording.2026-08-06.114033.mp4local models not available at deployment check #295 for reference |
Server env var OLLAMA_BASE_URL is not enough for Vercel deployments:
the server's localhost is Vercel's own machine, not the user's.
Each endpoint now accepts an optional ollama_url param that takes
precedence over the server default, letting users pass a tunnel URL
(e.g. ngrok) to reach their local Ollama from a deployed app.
- GET /models?ollama_url=...
- POST /model_info { ..., ollama_url: '...' }
- POST /chat (form field: ollama_url)
- POST /chat/stream (form field: ollama_url)
OLLAMA_BASE_URL env var is still used as the fallback, so local dev
and self-hosted instances need no changes.
Co-Authored-By: Claude <noreply@anthropic.com>
Owner
|
Still not working |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes Issue
Fixes #291
Description
The Ollama base URL was hardcoded as
http://localhost:11434across three files. When deployed (e.g. on Vercel),localhostresolves to the server's machine — not the user's — so local models are unreachable regardless of any server-side env var.What this PR does
Two-layer fix:
1. Server-side default (env var) —
OLLAMA_BASE_URLinConfigsets the fallback for self-hosted / Docker / local-dev setups. Zero changes needed for existing deployments.2. Per-request
ollama_urlparam — every Ollama-touching endpoint now accepts a user-supplied URL that takes precedence over the server default. The frontend can pass a tunnel address (e.g. ngrok) so the backend proxies the request to the user's local Ollama — bypassing browser mixed-content and CORS restrictions entirely.ollama_urlGET /models?ollama_url=POST /model_infoollama_urlPOST /chatollama_urlPOST /chat/streamollama_urlIf
ollama_urlis omitted, the server falls back toOLLAMA_BASE_URL(defaulthttp://localhost:11434), so local dev needs no changes.Type of change
Checklist
package.jsonorpackage-lock.jsonin this PRPackages Added (if any)
None
How to test
Prerequisites: Ollama installed and at least one model pulled (e.g.
ollama pull gemma3:1b).Test 1 — Default behaviour (no env var, no ollama_url param)
OLLAMA_BASE_URL.http://localhost:11434still works.Test 2 — Custom URL via env var (self-hosted / Docker)
OLLAMA_BASE_URLto your Ollama instance address, start the server.Test 3 — Per-request ollama_url (deployed instance → user's local Ollama)
ngrok http 11434ollama_urlin a/chator/chat/streamrequest — the server proxies through it and returns a reply.Test 4 — Invalid URL gracefully errors
Set
OLLAMA_BASE_URL(or passollama_url) to an unreachable address — confirm the app returns an error rather than crashing.What changed (files)
server/api/config.pyOLLAMA_BASE_URLviaos.getenv()with localhost defaultserver/api/services/ollama_services.pyollama_urlparamserver/api/routes/model_routes.py/modelsand/model_infoaccept and forwardollama_urlserver/api/routes/chat_routes.py/chatand/chat/streamaccept and forwardollama_urlserver/.env.example