How to hit the Ollama (local REST API) API

Ollama runs open models on your computer and serves a REST API at http://localhost:11434. Pull a model first (ollama pull <model>); {{MODEL}} is any model you have.

Authentication

None — it's your own machine. To call it from a web page like PostTaco, allow the page's origin: start Ollama with OLLAMA_ORIGINS=https://posttaco.dev, or use the PostTaco extension.

Full reference: https://github.com/ollama/ollama/blob/main/docs/api.md

List local models

curl http://localhost:11434/api/tags
Run in PostTaco

Generate text

stream: false returns one JSON object instead of a stream of lines.

curl http://localhost:11434/api/generate \
  -H "Content-Type: application/json" \
  -d '{"model": "{{MODEL}}", "prompt": "Why is the sky blue?", "stream": false}'
Run in PostTaco

Chat

curl http://localhost:11434/api/chat \
  -H "Content-Type: application/json" \
  -d '{"model": "{{MODEL}}", "messages": [{"role": "user", "content": "Hello!"}], "stream": false}'
Run in PostTaco