REST and OpenAI-compatible API
After install, Ollama serves two HTTP surfaces on the machine:
The API is not strictly versioned but is meant to stay backward compatible; rare deprecations land in release notes.
Native generate: /api/generate
Official example:
One-shot JSON (disable streaming):
Useful fields: system, options (temperature, num_ctx, …), keep_alive (0 unloads immediately). Default streaming is NDJSON—one JSON object per line, last line done: true.
Windows PowerShell (the Windows doc uses Invoke-WebRequest; this parses more cleanly):
If you want curl, call curl.exe so PowerShell does not rewrite it to Invoke-WebRequest.
Native chat: /api/chat
Send the full history in messages:
PowerShell is easier with a single-quoted body:
The assistant text is message.content. Vision models accept images (Base64)—see generate and chat.
Native embeddings: /api/embed
input is a string or an array of strings. ollama pull an embedding model first (Embeddings).
Management endpoints
OpenAI compatibility: /v1/chat/completions
Point an existing OpenAI SDK at a new base URL. Official examples use http://localhost:11434/v1/. api_key is required by the client but ignored locally—ollama is the usual placeholder.
The layer also implements /v1/completions, /v1/embeddings, /v1/models, and newer /v1/responses (needs a recent Ollama). Streaming, JSON mode, Base64 vision, tools, and reasoning effort are supported; not logprobs, remote image URLs, tool_choice, and several other fields. See the checklist on OpenAI compatibility.
OpenAI requests have no num_ctx. To change context, write a Modelfile with PARAMETER num_ctx and ollama create a new name.
Cloud API
Two patterns:
- Signed in locally:
ollama run gemma4:cloudor send a:cloudmodel tolocalhost:11434; the daemon forwards. - Direct cloud:
https://ollama.com/apiwithOLLAMA_API_KEYandAuthorization: Bearer ....
List models the cloud will serve: curl https://ollama.com/api/tags (auth rules follow the current docs).
Safety notes
- Default bind is localhost. Before
0.0.0.0, add network isolation or an authenticating proxy. - Compatibility
api_keyis not local access control. - Keep cloud keys in the environment, not the repo.