Client's host doesn't work when the host is behind a proxy server #124

Closed
opened 2026-02-15 16:28:09 -05:00 by yindo · 0 comments
Owner

Originally created by @orcahmlee on GitHub (Aug 5, 2024).

I hosted a Ollama server on a K8s using Helm Charts and I add a proxy server(APISix) for this deployment. Therefore, I can access the Ollama service via a host with path instead of using port-forwording.

For example, the url for the Ollama service is https://MY_HOST/ollama. I can access the Ollama API and get the response using curl:

curl https://MY_HOST/ollama/api/chat -d '{
  "model": "llama3",
  "stream": "false",
  "messages": [
    {
      "role": "user",
      "content": "who are you?"
    }
  ]
}'

However, I couldn't set the https://MY_HOST/ollama to the Client. The final url alway be parsed to https://MY_HOST:443 without the path ollama.

# This is the default value
client = Client(host="http://localhost:11434")
client._client.base_url  # URL('http://localhost:11434')

# This is the actual behavior
client = Client(host="https://MY_HOST/ollama")
client._client.base_url  # URL('https://MY_HOST')

# This is what I expected
client = Client(host="https://MY_HOST/ollama")
client._client.base_url  # URL('https://MY_HOST/ollama')

If this is reasonable, I could provide a PR for this feature.

Originally created by @orcahmlee on GitHub (Aug 5, 2024). I hosted a Ollama server on a K8s using Helm Charts and I add a proxy server(APISix) for this deployment. Therefore, I can access the Ollama service via a host with path instead of using port-forwording. For example, the url for the Ollama service is `https://MY_HOST/ollama`. I can access the Ollama API and get the response using curl: ```sh curl https://MY_HOST/ollama/api/chat -d '{ "model": "llama3", "stream": "false", "messages": [ { "role": "user", "content": "who are you?" } ] }' ``` However, I couldn't set the `https://MY_HOST/ollama` to the `Client`. The final url alway be parsed to `https://MY_HOST:443` without the path `ollama`. ```python # This is the default value client = Client(host="http://localhost:11434") client._client.base_url # URL('http://localhost:11434') # This is the actual behavior client = Client(host="https://MY_HOST/ollama") client._client.base_url # URL('https://MY_HOST') # This is what I expected client = Client(host="https://MY_HOST/ollama") client._client.base_url # URL('https://MY_HOST/ollama') ``` ------ If this is reasonable, I could provide a PR for this feature.
yindo closed this issue 2026-02-15 16:28:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#124