Skip to content

fix: make Ollama base URL configurable via OLLAMA_BASE_URL env var - #309

Closed
arnavgoel17 wants to merge 2 commits into
Rucha-Ambaliya:mainfrom
arnavgoel17:fix/ollama-configurable-base-url
Closed

fix: make Ollama base URL configurable via OLLAMA_BASE_URL env var#309
arnavgoel17 wants to merge 2 commits into
Rucha-Ambaliya:mainfrom
arnavgoel17:fix/ollama-configurable-base-url

Conversation

@arnavgoel17

@arnavgoel17 arnavgoel17 commented Aug 4, 2026

Copy link
Copy Markdown

Fixes Issue

Fixes #291

Description

The Ollama base URL was hardcoded as http://localhost:11434 across three files. When deployed (e.g. on Vercel), localhost resolves 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_URL in Config sets the fallback for self-hosted / Docker / local-dev setups. Zero changes needed for existing deployments.

2. Per-request ollama_url param — 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.

Endpoint How to pass ollama_url
GET /models query param ?ollama_url=
POST /model_info JSON body field ollama_url
POST /chat form field ollama_url
POST /chat/stream form field ollama_url

If ollama_url is omitted, the server falls back to OLLAMA_BASE_URL (default http://localhost:11434), so local dev needs no changes.

Type of change

  • 🐛 Bug fix

Checklist

  • I am a ECSoC'26 contributor
  • My code follows the project's style guidelines
  • I have added comments in areas that may be hard to understand
  • I have NOT included package.json or package-lock.json in this PR

Packages 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)

  1. Start the server without setting OLLAMA_BASE_URL.
  2. Open the app, select a local model, send a message.
  3. Response comes back normally — default http://localhost:11434 still works.

Test 2 — Custom URL via env var (self-hosted / Docker)

  1. Set OLLAMA_BASE_URL to your Ollama instance address, start the server.
  2. Send a message with a local model — same result expected.

Test 3 — Per-request ollama_url (deployed instance → user's local Ollama)

  1. Expose your local Ollama via ngrok: ngrok http 11434
  2. Call the models endpoint with the tunnel URL:
    GET /models?ollama_url=https://<your-ngrok-id>.ngrok-free.app
    
  3. Your local models should appear in the response, even though the server is remote.
  4. Pass the same ollama_url in a /chat or /chat/stream request — the server proxies through it and returns a reply.

Test 4 — Invalid URL gracefully errors

Set OLLAMA_BASE_URL (or pass ollama_url) to an unreachable address — confirm the app returns an error rather than crashing.

What changed (files)

File Change
server/api/config.py OLLAMA_BASE_URL via os.getenv() with localhost default
server/api/services/ollama_services.py Both functions accept optional ollama_url param
server/api/routes/model_routes.py /models and /model_info accept and forward ollama_url
server/api/routes/chat_routes.py /chat and /chat/stream accept and forward ollama_url
server/.env.example Updated docs explaining server default vs per-request param

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
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

@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.

@Rucha-Ambaliya

Copy link
Copy Markdown
Owner

Follow the pr template please

@arnavgoel17

Copy link
Copy Markdown
Author

Follow the pr template please

Could you please elaborate a lil? I'm new to this repo.

@Rucha-Ambaliya

Copy link
Copy Markdown
Owner

@Rucha-Ambaliya

Copy link
Copy Markdown
Owner

Also please attach a video of testing, and/or a guide on how to test it

@arnavgoel17

Copy link
Copy Markdown
Author

Heyy @Rucha-Ambaliya, I have edited the pr template as described.

@Rucha-Ambaliya

Copy link
Copy Markdown
Owner
Recording.2026-08-06.114033.mp4

local 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>
@Rucha-Ambaliya

Copy link
Copy Markdown
Owner

Still not working
Until you don't connect with user's machine directly, assigning direct ollama url most probably won't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEATURE: Support local Ollama models from the deployed web application

2 participants