Ollama APIs: REST and OpenAI-Compatible
Harry
· 13 Sep 2026
· 2 views
The Local HTTP API
Ollama listens on port 11434 by default. Any language can send a generate request over HTTP.
curl http://localhost:11434/api/generate
-d '{"model": "llama3.2", "prompt": "Explain recursion in one sentence", "stream": false}'OpenAI-Compatible Endpoint
Point existing OpenAI clients at Ollama by swapping the base URL. Code and tools that speak OpenAI work unchanged.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1")
reply = client.chat.completions.create(
model="llama3.2",
messages=[{"role": "user", "content": "Say hello in five languages"}],
)
print(reply.choices[0].message.content)Official Python Client
pip install ollama
import ollama
resp = ollama.generate(model="llama3.2", prompt="Write a haiku about waves")
print(resp["response"])Streaming
Most endpoints stream tokens by default. Set stream to false when you only need the final answer, and keep it true for chat-style interfaces.
Key Points
- The API lives at localhost:11434.
- /v1 endpoints speak the OpenAI format.
- The ollama Python client wraps the REST API.
- Disable streaming for one-shot, scripted calls.