Ollama and Open WebUI at UiS
UiS hosts open language models that you can use from the browser through Open WebUI, or from your own code through the Ollama API. This page covers getting a key, checking that it works, and calling the API from cURL and Python.
| Service | Address | Status |
|---|---|---|
| Ollama API | ollama.ux.uis.no | |
| Open WebUI | openwebui.ux.uis.no |
- 1Get an API key
- 2Check the connection
- 3cURL examples
- 4Python examples
- 5OpenAI-compatible API
- 6Troubleshooting
1Get an API key
Log in to Open WebUI with your UiS credentials and generate a key under Settings → Account. The same key works for the Ollama API.
Keep the key in an environment variable rather than in your code. The examples on this page read it from
OLLAMA_API_KEY.
# macOS / Linux
export OLLAMA_API_KEY="your-key-here"
# Windows (PowerShell)
$env:OLLAMA_API_KEY = "your-key-here"
Don't commit the key to version control.
2Check the connection
The status endpoint needs no key:
curl https://ollama.ux.uis.no/status
It should reply:
Ollama is running
To list the models your key can use:
curl https://ollama.ux.uis.no/api/tags \
-H "Authorization: Bearer $OLLAMA_API_KEY"
llama3:8b is open to everyone. Other models are private and need extra permissions after you
sign up. To get access to one, or to suggest a new model, email Jostein Hagen Lindhom
(jostein.lindhom@uis.no) or Theodor Ivesdal
(theodor.ivesdal@uis.no).
3cURL examples
A single prompt with /api/generate
curl https://ollama.ux.uis.no/api/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OLLAMA_API_KEY" \
-d '{
"model": "llama3:8b",
"prompt": "What is the capital of Norway?",
"stream": false
}'
A conversation with /api/chat
Send the whole message history with each request.
curl https://ollama.ux.uis.no/api/chat \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OLLAMA_API_KEY" \
-d '{
"model": "llama3:8b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of Norway?"}
],
"stream": false
}'
Both endpoints stream by default, sending one JSON object per line as the text is generated. With
"stream": false you get the whole answer in one response.
4Python examples
You need Python 3.8 or newer and the ollama package
(pip install ollama).
import os
from ollama import Client
client = Client(
host="https://ollama.ux.uis.no",
headers={"Authorization": f"Bearer {os.environ['OLLAMA_API_KEY']}"},
)
# Single prompt
resp = client.generate(model="llama3:8b", prompt="What is the capital of Norway?")
print(resp.response)
# Conversation
resp = client.chat(
model="llama3:8b",
messages=[{"role": "user", "content": "What is the capital of Norway?"}],
)
print(resp.message.content)
# Streaming: print the answer as it is generated
for chunk in client.chat(
model="llama3:8b",
messages=[{"role": "user", "content": "Write a haiku about Stavanger."}],
stream=True,
):
print(chunk.message.content, end="", flush=True)
More in the Ollama documentation.
5OpenAI-compatible API
Code written for the OpenAI SDK, LangChain and similar tools can use the base URL
https://ollama.ux.uis.no/api. Only chat completions and the model list are available.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://ollama.ux.uis.no/api",
api_key=os.environ["OLLAMA_API_KEY"],
)
resp = client.chat.completions.create(
model="llama3:8b",
messages=[{"role": "user", "content": "What is the capital of Norway?"}],
)
print(resp.choices[0].message.content)
This endpoint is provided by Open WebUI; see its API documentation.
6Troubleshooting
- 401 Unauthorized
- The key is wrong or missing. Check that
OLLAMA_API_KEYis set in the shell you're running from. - 404 or 5xx
- Check the status column at the top of the page. If a service is down, email one of the contacts in section 2.
- Model not found
- The model name must match
/api/tagsexactly:llama3:8b, notllama3. - A model is missing from
/api/tags - It's probably private. Ask one of the contacts in section 2 for access.