Python for a public Ollama server
A short urllib client for /api/chat on port 11434.
The Ollama Python library is convenient when you already depend on it. The standard library is enough for a test. Build a POST to /api/chat, send JSON, and read the body. The message you want is message.content in the response, next to done: true.
Point the URL at the host and port, not at a path you invented. This server is http://datattention.com:11434/api/chat. The model name can be llama3.2. GET /api/tags shows llama3.2:latest.
Do not set an API key header. A timeout of about 30 seconds is enough for this host, which answers immediately.
On this host
This is the whole client. It talks to the public listener on datattention.com port 11434.
import json, urllib.request
req = urllib.request.Request(
"http://datattention.com:11434/api/chat",
data=json.dumps({
"model": "llama3.2",
"stream": False,
"messages": [{"role": "user", "content": "Hello"}],
}).encode(),
headers={"Content-Type": "application/json"},
)
print(urllib.request.urlopen(req, timeout=30).read().decode())
The full list of ports and paths is on the endpoints page.