1. Learn
  2. Run and serve it

Ollama API guide: curl examples and the OpenAI-compatible endpoint

Use Ollama from code. Working curl examples for /api/generate, /api/chat and the OpenAI-compatible /v1/chat/completions, plus the options that matter.

Updated Oct 26, 2026 · RunItLocal.io

Ollama runs a web API on http://localhost:11434 the whole time it's running. It has two flavors: Ollama's own API under /api/, and an OpenAI-compatible one under /v1/. Use the OpenAI one when an app or library already speaks OpenAI. Use the native one when you need Ollama-specific options like context length.

All examples below use Qwen3 8B. Pull it first with ollama pull qwen3:8b.

Check it's running

curl http://localhost:11434

It answers "Ollama is running". To list the models you have:

curl http://localhost:11434/api/tags

/api/generate: one prompt, one answer

curl http://localhost:11434/api/generate -d '{"model":"qwen3:8b","prompt":"Why is the sky blue? One sentence.","stream":false}'

The answer is in the response field. Without "stream":false, Ollama streams the reply as one JSON object per line, which is what you want for a chat interface but awkward in a script.

/api/chat: a conversation

curl http://localhost:11434/api/chat -d '{"model":"qwen3:8b","messages":[{"role":"system","content":"Answer briefly."},{"role":"user","content":"What is a GPU?"}],"stream":false}'

The API keeps no memory between calls. To continue a conversation, send the whole message list again with the model's last reply added as {"role":"assistant","content":"..."}. The reply is in message.content.

/v1/chat/completions: the OpenAI-compatible endpoint

curl http://localhost:11434/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"qwen3:8b","messages":[{"role":"user","content":"Write a haiku about memory bandwidth."}]}'

The reply looks exactly like OpenAI's: the text is in choices[0].message.content. That means most OpenAI client libraries work unchanged. Set the base URL to http://localhost:11434/v1 and the API key to any non-empty string, like ollama. The key is required by the libraries, but Ollama ignores it.

There's also /v1/models for listing models and /v1/embeddings for embeddings.

Options worth knowing

On the native endpoints, put model settings in an options object:

curl http://localhost:11434/api/chat -d '{"model":"qwen3:8b","messages":[{"role":"user","content":"Summarize this."}],"stream":false,"options":{"num_ctx":16384,"temperature":0.2}}'
FieldWhereWhat it does
options.num_ctx/api/Context length in tokens. The default is short.
options.temperature/api/Lower is more focused and repeatable
format/api/"json" forces valid JSON output
keep_alive/api/How long the model stays loaded, like "10m", or -1 for always
streambothfalse returns one complete reply

The OpenAI endpoint doesn't take num_ctx. If you use /v1/ with long prompts, raise the context on the server side instead; see increasing Ollama's context length. Long prompts that don't fit get cut off without an error, so this matters for document work.

Speed numbers come free

A non-streamed reply from /api/generate or /api/chat includes timing fields. eval_count is tokens generated and eval_duration is the time in nanoseconds, so tokens per second is eval_count / eval_duration * 1e9. That's an easy way to check your card against our calculator. Here's what it estimates for an RTX 3090:

RTX 3090, 24 GB · estimated with our calculator · full page

  • Qwen3 4BQuick everyday chat and summaries
    ~210 tok/s
    Runs greatqwen3:4b
  • Qwen3 8BA solid all-rounder for chat and writing
    ~99 tok/s
    Runs greatqwen3:8b
  • Gemma 3 12BReads images as well as text
    ~64 tok/s
    Runs greatgemma3:12b
  • Qwen3 14BNoticeably smarter at reasoning and code
    ~55 tok/s
    Runs greatqwen3:14b
  • gpt-oss 20BOpenAI's open model. Fast, strong reasoning
    ~160 tok/s
    Runs greatgpt-oss:20b
  • Gemma 3 27BGoogle's best open model for its size
    ~30 tok/s
    Runs greatgemma3:27b
  • Qwen3 30B-A3B30B smarts at small-model speed
    ~160 tok/s
    Runs greatqwen3:30b
  • Qwen3 32BStrong coding and long answers
    ~26 tok/s
    Usableqwen3:32b
  • Llama 3.3 70BClose to the big cloud models
    needs 45 GB
    Too bigllama3.3:70b
  • gpt-oss 120BOpenAI's largest open model
    needs 67 GB
    Too biggpt-oss:120b
  • Qwen3 235B-A22BAlibaba's flagship open model, for multi-GPU rigs
    needs 144 GB
    Too bigqwen3:235b
  • DeepSeek R1 671BThe full DeepSeek R1, for the biggest rigs
    needs 406 GB
    Too bigdeepseek-r1:671b

If your measured number is far below the estimate, the model may be partly on the CPU. Run ollama ps and see fixing Ollama using the CPU.

Calling it from another machine

By default the API only listens on your own computer. To reach it from a phone or another PC, see Ollama on your network. Ollama has no logins or API keys of its own, so read securing your local AI server before you open it up.

Where to go next