AI

Ollama Commands Cheat Sheet: CLI and API Reference

Every time you need the exact flag for embedding truncation or the right curl for the chat endpoint, the official docs send you through five different pages. This cheat sheet is the single reference we keep coming back to. It covers every Ollama CLI command and REST API endpoint, with tested examples you can copy and run.

Original content from computingforgeeks.com - post 164411

Ollama has changed a lot since this page first went up. Running ollama with no arguments now opens an interactive coding agent, ollama launch hands a local model to Claude Code, ChatGPT, OpenCode and a dozen other integrations, and the inference engine underneath moved to llama.cpp, which widened GGUF model support and changed several outputs you see below. If you still need installation instructions, see Install Ollama on Rocky Linux / Ubuntu. To decide which model deserves your disk space, the Ollama models cheat sheet and the open source LLM comparison table cover the field.

Every command, API response and SDK snippet on this page was re-run on Ollama 0.32.6 on Ubuntu 24.04 in August 2026, on a CPU-only 6-core test VM. Outputs come from those runs, lightly trimmed for readability, so the timing numbers reflect CPU inference; on a GPU the same commands print higher rates.

Model Management

These commands handle downloading, inspecting, copying, and removing models from the local registry.

Pull a model

Downloads a model from the Ollama library. Tag defaults to latest if omitted.

ollama pull gemma3:4b

List local models

Shows all models stored on disk with their size and last modified time.

ollama list

The output includes the model ID, size, and when it was last updated:

NAME                       ID              SIZE      MODIFIED
nomic-embed-text:latest    0a109f422b47    274 MB    About a minute ago
qwen3:1.7b                 8f68893c685c    1.4 GB    2 minutes ago
gemma3:4b                  a2af6cc3eb7f    3.3 GB    4 minutes ago

List running models

Shows models currently loaded in memory, including processor allocation and context size.

ollama ps

On a CPU-only system, all processing runs on the CPU:

NAME         ID              SIZE      PROCESSOR    CONTEXT    UNTIL
gemma3:4b    a2af6cc3eb7f    2.9 GB    100% CPU     4096       4 minutes from now

The PROCESSOR column is the fastest way to confirm whether a model actually landed on your GPU or silently fell back to CPU. If you keep seeing 100% CPU on hardware you expected more from, the mini PC for local AI comparison shows what different memory and GPU configurations deliver in practice.

Show model details

Displays architecture, parameter count, quantization, context length, and license info.

ollama show gemma3:4b

Output confirms the model architecture and capabilities:

  Model
    architecture        gemma3
    parameters          4.3B
    context length      131072
    embedding length    2560
    quantization        Q4_K_M

  Capabilities
    completion
    vision

  Parameters
    stop           "<end_of_turn>"
    temperature    1
    top_k          64
    top_p          0.95

  License
    Gemma Terms of Use
    Last modified: February 21, 2024
    ...

You can also extract specific sections with flags. The --system flag prints the baked-in system prompt (empty for stock gemma3), and -v dumps detailed metadata:

ollama show gemma3:4b --modelfile
ollama show gemma3:4b --parameters
ollama show gemma3:4b --template
ollama show gemma3:4b --system
ollama show gemma3:4b --license
ollama show gemma3:4b -v

Copy a model

Creates a new reference to an existing model. Useful for creating custom variants without re-downloading weights.

ollama cp gemma3:4b mymodel:latest

Both names now point to the same model ID:

copied 'gemma3:4b' to 'mymodel:latest'

Remove a model

Deletes a model from disk. The blob files are only removed when no other model references them.

ollama rm mymodel:latest

Confirmation:

deleted 'mymodel:latest'

Stop a running model

Unloads a model from memory without stopping the Ollama server.

ollama stop gemma3:4b

Running Models

The ollama run command handles both interactive chat sessions and one-shot prompts from the command line.

Interactive chat

Opens an interactive session. Type /bye to exit.

ollama run gemma3:4b

One-shot prompt

Pass the prompt as a second argument. Ollama prints the response and exits.

ollama run gemma3:4b "What port does PostgreSQL use?"

Piped input

Pipe text from another command or file. Great for scripting.

echo "What is the capital of France?" | ollama run gemma3:4b

Response:

The capital of France is **Paris**.

JSON output

Force the model to respond with valid JSON using --format json. Include “JSON” in your prompt so the model understands what structure you want.

echo "List 3 Linux distributions. Return JSON array with name and year fields." | ollama run gemma3:4b --format json

The model returns structured JSON:

{
  "distributions": [
    {"name": "Ubuntu", "year": 2004},
    {"name": "Debian", "year": 1993},
    {"name": "Fedora", "year": 2003}
  ]
}

Verbose output with timing stats

Add --verbose to see token generation speed and load times. Useful for benchmarking.

ollama run gemma3:4b --verbose "What is 2+2? Reply with just the number."

After the response, timing stats are printed:

4

total duration:       1.548823849s
load duration:        637.491263ms
prompt eval count:    23 token(s)
prompt eval duration: 680.723ms
prompt eval rate:     33.79 tokens/s
eval count:           3 token(s)
eval duration:        224.596ms
eval rate:            13.36 tokens/s

The eval rate line is the number that tells you whether your hardware keeps up with your models. 13 tokens per second on a 6-core CPU is usable for short prompts and painful for long ones. When that number pushes you toward buying hardware, the GPU guide for local LLMs ranks cards by measured inference throughput rather than gaming benchmarks.

Keep model loaded

By default, models unload after 5 minutes of inactivity. Override this with --keepalive.

ollama run gemma3:4b --keepalive 30m "Hello"

Set to -1 to keep a model loaded indefinitely, or 0 to unload immediately after the request. ollama ps confirms the new expiry, showing “29 minutes from now” in the UNTIL column after the command above.

Thinking mode (DeepSeek R1, Qwen3, gpt-oss)

Reasoning models emit a chain-of-thought block before the final answer. The --think flag takes true, false, or high/medium/low levels on models that support graded effort, and --hidethinking suppresses the trace from the visible output while still letting the model reason internally.

# Force thinking on
echo "What is 13 * 17?" | ollama run deepseek-r1:1.5b --think=true

# Show the answer only, hide the chain of thought
echo "What is 13 * 17?" | ollama run deepseek-r1:1.5b --hidethinking

With thinking on, the CLI wraps the trace in Thinking... and ...done thinking. markers before printing the answer (221, in case you wondered). With --hidethinking the markers and the trace disappear and only the answer prints. The token cost does not disappear with it: the model still generates the full trace, so on slow hardware --think=false is the latency lever, not --hidethinking.

Embeddings from the CLI

Embedding models like nomic-embed-text output 768-dim vectors by default. Pass --dimensions to truncate (Matryoshka-style) for cheaper storage in your vector DB. A related flag, --truncate, controls what happens when input exceeds the model’s context: it defaults to true, and --truncate=false makes Ollama error instead of silently cutting your text.

echo "the quick brown fox" | ollama run nomic-embed-text --dimensions 256

The raw vector prints to stdout, ready to pipe into whatever ingests it:

[-0.07424739,0.01747685,-0.21929774,-0.005974844,-0.0014804383,...]

The interactive agent (bare ollama)

Running ollama with no arguments no longer prints help. Since the 0.32 series it opens a full-screen agent TUI that can chat, write code, search the web, and delegate work to a model of your choice. The old preview flags from earlier releases (--experimental, --experimental-websearch, --experimental-yolo) are gone; the agent workflow replaced them.

ollama

Two things to know before you rely on it. It needs a real terminal: over a bare SSH exec channel (no pty) it exits with could not open a new TTY: open /dev/tty: no such device or address, so scripts cannot drive it. And the built-in web search and fetch tools require an ollama.com account; the agent tells you to run ollama signin when it needs one.

Server Management

Ollama runs as a systemd service on Linux. These commands cover starting, stopping, and configuring the server.

Start the server manually

If you need to run Ollama outside of systemd (for debugging, for example), serve also answers to the alias start:

ollama serve

Systemd service commands

The standard install creates an ollama.service unit. Manage it with systemctl:

sudo systemctl start ollama
sudo systemctl stop ollama
sudo systemctl restart ollama
sudo systemctl status ollama

The status output is more interesting than it used to be. Since the engine change, a loaded model shows up as a separate llama-server child process under the service, with its runtime flags visible:

● ollama.service - Ollama Service
     Loaded: loaded (/etc/systemd/system/ollama.service; enabled; preset: enabled)
     Active: active (running) since Thu 2026-08-06 13:53:24 UTC; 7min ago
   Main PID: 1460 (ollama)
      Tasks: 28 (limit: 14307)
     Memory: 5.6G (peak: 10.3G)
        CPU: 7min 3.998s
     CGroup: /system.slice/ollama.service
             ├─1460 /usr/local/bin/ollama serve
             └─6144 /usr/local/lib/ollama/llama-server --model /usr/share/ollama/.ollama/models/blobs/sha256-970aa... --port 33775 --host 127.0.0.1 --no-webui --offline -c 2048 -np 1 --flash-attn auto --embedding

View logs

Check the journal for errors, request logs, and model load events:

sudo journalctl -u ollama -f

Sample log entries showing API requests:

Aug 06 14:01:10 ollama-host ollama[1460]: [GIN] 2026/08/06 - 14:01:10 | 200 |  103.965898ms |       127.0.0.1 | POST     "/api/generate"
Aug 06 14:01:10 ollama-host ollama[1460]: [GIN] 2026/08/06 - 14:01:10 | 200 |     743.732µs |       127.0.0.1 | GET      "/api/tags"
Aug 06 14:01:10 ollama-host ollama[1460]: [GIN] 2026/08/06 - 14:01:10 | 200 |      29.705µs |       127.0.0.1 | HEAD     "/"

Set environment variables via systemd override

To configure Ollama to listen on all interfaces or change the model storage path, create a systemd override file:

sudo systemctl edit ollama

Add the environment variables you need between the comments:

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_MODELS=/data/ollama/models"
Environment="OLLAMA_NUM_PARALLEL=4"
Environment="OLLAMA_FLASH_ATTENTION=1"

Reload and restart for changes to take effect:

sudo systemctl daemon-reload
sudo systemctl restart ollama

Sign in, sign out, and launch integrations

Three commands tie the local CLI to ollama.com and to coding agents. signin authenticates against your Ollama account (required to push a model, run cloud models, or use the agent’s web search), signout revokes the local credential, and launch opens the interactive menu or hands a model directly to a registered integration.

ollama signin
ollama signout

ollama launch                 # interactive menu
ollama launch claude          # hand off to Claude Code
ollama launch chatgpt         # ChatGPT app (formerly codex-app)
ollama launch opencode        # OpenCode
ollama launch claude --model qwen3:1.7b
ollama launch codex -- --sandbox workspace-write

On a headless server ollama signin prints the connect URL instead of opening a browser:

You need to be signed in to Ollama to run Cloud models.

If your browser did not open, navigate to:
    https://ollama.com/connect?name=your-host&key=...

The integration list has grown well past the handful of coding agents it started with. The current release recognizes claude (Claude Code), chatgpt (with codex-app, codex-desktop and codex-gui as aliases), codex, opencode, copilot, hermes, hermes-desktop, openclaw, omp, droid, kimi, pi, pool, cline, qwen, and vscode. Useful flags: --model picks the model, --config configures without launching, --restore returns an integration to its default profile, and -y auto-answers confirmation prompts. Launching an aging model like CodeLlama or a base DeepSeek-R1 tag now triggers a deprecation warning before it proceeds.

REST API: Generate and Chat

The Ollama API listens on port 11434 by default. All endpoints accept JSON. Set "stream": false to get the complete response in a single JSON object instead of a stream of tokens.

POST /api/generate

Single-turn text generation. Takes a prompt string and returns a completion.

curl -s http://localhost:11434/api/generate -d '{
  "model": "gemma3:4b",
  "prompt": "Why is the sky blue? Answer in one sentence.",
  "stream": false
}'

Response JSON (the context token array is trimmed for readability):

{
  "model": "gemma3:4b",
  "created_at": "2026-08-06T14:02:00.530203624Z",
  "response": "The sky appears blue due to a phenomenon called Rayleigh scattering, where shorter wavelengths of sunlight (blue and violet) are scattered more by the Earth's atmosphere than longer wavelengths like red and yellow.",
  "done": true,
  "done_reason": "stop",
  "context": [105, 2430, 107, ...],
  "total_duration": 12143420365,
  "load_duration": 6685291601,
  "prompt_eval_count": 21,
  "prompt_eval_duration": 1051615000,
  "eval_count": 40,
  "eval_duration": 4403651000
}

Durations are in nanoseconds. Divide eval_count by eval_duration (converted to seconds) for tokens per second; the response above works out to 9.1 tok/s of generation on the CPU test box, with more than half of total_duration spent loading the model on first request.

POST /api/chat

Multi-turn conversation endpoint. Pass a messages array with role/content pairs, just like the OpenAI Chat API format.

curl -s http://localhost:11434/api/chat -d '{
  "model": "gemma3:4b",
  "messages": [
    {"role": "system", "content": "You are a Linux sysadmin. Be brief."},
    {"role": "user", "content": "What is DNS?"}
  ],
  "stream": false
}'

The response wraps the assistant message in a message object:

{
  "model": "gemma3:4b",
  "created_at": "2026-08-06T14:02:05.957278096Z",
  "message": {
    "role": "assistant",
    "content": "DNS translates human-readable domain names (like google.com) into IP addresses computers use to communicate."
  },
  "done": true,
  "done_reason": "stop",
  "total_duration": 5411831837,
  "load_duration": 542911255,
  "prompt_eval_count": 30,
  "eval_count": 35
}

POST /api/generate with JSON format

Force structured JSON output by setting "format": "json" in the request body. The model will only return valid JSON.

curl -s http://localhost:11434/api/generate -d '{
  "model": "gemma3:4b",
  "prompt": "List 3 Linux distributions. Return JSON array with name and year fields.",
  "format": "json",
  "stream": false
}'

The response field contains valid JSON that you can parse directly:

{
  "distributions": [
    {"name": "Ubuntu", "year": 2004},
    {"name": "Debian", "year": 1993},
    {"name": "Fedora", "year": 2003}
  ]
}

GET /api/tags

Lists all models available locally. Same data as ollama list but in JSON, and the entries now carry more metadata than they used to: a capabilities array plus context_length and embedding_length inside details.

curl -s http://localhost:11434/api/tags | python3 -m json.tool

Each model entry includes its digest, size, parameter count, quantization level, and what it can do:

{
  "models": [
    {
      "name": "deepseek-r1:1.5b",
      "model": "deepseek-r1:1.5b",
      "modified_at": "2026-08-06T13:59:57.513538096Z",
      "size": 1117322768,
      "digest": "e0979632db5a88d1a53884cb2a941772d10ff5d055aabaa6801c4e36f3a6c2d7",
      "details": {
        "format": "gguf",
        "family": "qwen2",
        "parameter_size": "1.8B",
        "quantization_level": "Q4_K_M",
        "context_length": 131072,
        "embedding_length": 1536
      },
      "capabilities": ["completion", "thinking"]
    }
  ]
}

POST /api/show

Returns detailed model metadata: parameters, template, license, and the full model_info block with architecture details. Responses from this endpoint are cached server-side, so integrations that poll it (VS Code, for example) get answers in microseconds after the first hit.

curl -s http://localhost:11434/api/show -d '{"model": "gemma3:4b"}' | python3 -m json.tool

POST /api/embed

Generates vector embeddings for text input. Requires a model that supports embeddings (such as nomic-embed-text or all-minilm). General chat models like gemma3 do not support this endpoint.

curl -s http://localhost:11434/api/embed -d '{
  "model": "nomic-embed-text",
  "input": "Ollama runs large language models locally"
}'

The response contains an embeddings array (one 768-float vector for the input above) along with total_duration, load_duration and prompt_eval_count fields. The vectors can go straight into PostgreSQL with pgvector for similarity search and RAG applications.

GET /api/version

Returns the running Ollama version. Useful for health checks and version-gated feature detection.

curl -s http://localhost:11434/api/version

One line back:

{"version":"0.32.6"}

GET /api/ps

Returns the list of currently loaded models. Same data as ollama ps in JSON, including how much of the model sits in VRAM versus system RAM.

curl -s http://localhost:11434/api/ps | python3 -m json.tool

On the CPU test box size_vram is zero; on a GPU host it shows the offloaded bytes:

{
  "models": [
    {
      "name": "gemma3:4b",
      "model": "gemma3:4b",
      "size": 2881811905,
      "digest": "a2af6cc3eb7fa8be8504abaf9b04e88f17a119ec3f04a3addf55f92841195f5a",
      "expires_at": "2026-08-06T14:27:56.41451943Z",
      "size_vram": 0,
      "context_length": 4096
    }
  ]
}

POST /api/chat with tool calling

Tool-capable models (check the capabilities array in /api/tags for “tools”) accept a tools array describing functions they can call. The response either answers directly or returns a tool_calls array with the chosen function and parsed arguments. You execute the function on your side and post the result back as a tool role message to continue the conversation.

curl -s http://localhost:11434/api/chat -d '{
  "model": "qwen3:1.7b",
  "stream": false,
  "messages": [{"role":"user","content":"What is the weather in Nairobi?"}],
  "tools": [{
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "Get current weather for a city",
      "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }
  }]
}' | python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin)['message'].get('tool_calls'), indent=2))"

Real response from Qwen3 1.7B on the test box:

[
  {
    "id": "call_8azcwhif",
    "function": {
      "index": 0,
      "name": "get_weather",
      "arguments": {"city": "Nairobi"}
    }
  }
]

POST /api/chat with structured outputs

Pass a JSON Schema in the format field and the response is constrained to match it. This is stricter than the older "format":"json" shorthand because the schema enforces field names, types, and required fields.

curl -s http://localhost:11434/api/chat -d '{
  "model": "qwen3:1.7b",
  "stream": false,
  "messages": [{"role":"user","content":"Pick a city and report plausible weather. Output JSON only."}],
  "format": {
    "type": "object",
    "properties": {
      "city": {"type": "string"},
      "temp_c": {"type": "number"},
      "condition": {"type": "string"}
    },
    "required": ["city","temp_c","condition"]
  }
}'

Real output, valid against the schema on the first try:

{
  "city": "Seattle",
  "temp_c": 12,
  "condition": "Partly cloudy with a chance of light rain in the evening"
}

REST API: OpenAI-Compatible Endpoints

Ollama exposes OpenAI-compatible endpoints at /v1/. This lets you point any OpenAI SDK or tool at your local Ollama instance by changing the base URL.

GET /v1/models

Lists available models in the OpenAI format.

curl -s http://localhost:11434/v1/models | python3 -m json.tool

Response follows the OpenAI schema:

{
  "object": "list",
  "data": [
    {
      "id": "gemma3:4b",
      "object": "model",
      "created": 1786024553,
      "owned_by": "library"
    }
  ]
}

POST /v1/chat/completions

Drop-in replacement for the OpenAI Chat Completions API. Works with the official openai Python SDK by setting base_url="http://localhost:11434/v1".

curl -s http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemma3:4b",
    "messages": [
      {"role": "user", "content": "What port does SSH use?"}
    ]
  }'

The response matches the OpenAI format with choices and usage fields:

{
  "id": "chatcmpl-552",
  "object": "chat.completion",
  "created": 1786024976,
  "model": "gemma3:4b",
  "system_fingerprint": "fp_ollama",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "SSH typically uses TCP port 22, but it can be configured to run on a different port."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 22,
    "total_tokens": 41
  }
}

Streaming with usage reporting

Streaming now matches OpenAI’s wire format exactly: role arrives only on the first chunk, finish_reason gets its own chunk, and token usage arrives in a final separate chunk when you set stream_options.include_usage. Truncated responses report finish_reason: "length". If a client library worked against the real OpenAI API, it parses Ollama’s stream unmodified.

curl -sN http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemma3:4b",
    "stream": true,
    "stream_options": {"include_usage": true},
    "messages": [{"role": "user", "content": "Say OK"}]
  }'

The tail of the stream shows the separate finish and usage chunks:

data: {"id":"chatcmpl-747","object":"chat.completion.chunk","created":1786024977,"model":"gemma3:4b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"chatcmpl-747","object":"chat.completion.chunk","created":1786024977,"model":"gemma3:4b","system_fingerprint":"fp_ollama","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":3,"total_tokens":15}}

data: [DONE]

REST API: Model Management

These endpoints let you manage models programmatically, which is useful for automation scripts and deployment pipelines.

POST /api/pull

Pull a model via the API. Equivalent to ollama pull from the CLI.

curl -s http://localhost:11434/api/pull -d '{
  "model": "gemma3:4b",
  "stream": false
}'

Returns {"status": "success"} when complete.

POST /api/copy

Copy a model to a new name. Returns HTTP 200 with an empty body on success.

curl -s -X POST http://localhost:11434/api/copy -d '{
  "source": "gemma3:4b",
  "destination": "gemma3-backup"
}'

DELETE /api/delete

Delete a model. Returns HTTP 200 on success.

curl -s -X DELETE http://localhost:11434/api/delete -d '{
  "model": "gemma3-backup"
}'

POST /api/create

Build a custom model directly from an inline body, no Modelfile on disk required. The server returns a stream of status events. Use this when your control plane wants to provision custom models without shipping files around.

curl -X POST http://localhost:11434/api/create -d '{
  "model": "json-bot",
  "from": "qwen3:1.7b",
  "system": "You answer in JSON only. No prose.",
  "parameters": {"temperature": 0.0, "num_ctx": 8192}
}'

The status stream ends with success:

{"status":"creating new layer sha256:b42154872030ac98d309177504f8715cb3bccb1f846a02e7e6daf7f5d1c705f4"}
{"status":"writing manifest"}
{"status":"success"}

POST /api/push

Upload a local model to ollama.com. Requires ollama signin first. Streams progress events as JSON. The model name must use your namespace, for example youruser/coder-strict.

curl -X POST http://localhost:11434/api/push -d '{
  "model": "youruser/coder-strict",
  "stream": true
}'

Modelfile Reference

A Modelfile defines a custom model: its base weights, system prompt, parameters, and template. Create one to build reusable model configurations.

Example Modelfile

Save this as Modelfile in your working directory:

FROM gemma3:4b
SYSTEM "You are a Linux systems administrator. Answer questions about Linux concisely."
PARAMETER temperature 0.7
PARAMETER top_p 0.9

Build the custom model from the Modelfile:

ollama create sysadmin-bot -f Modelfile

# Quantize while creating, in one step (requires an F16, BF16 or F32 source model)
ollama create sysadmin-bot-q4 -f Modelfile -q q4_K_M

The -q / --quantize flag runs the quantization at build time. The supported targets are narrower than they used to be: q4_K_S, q4_K_M, and q8_0. The source model must be F16, BF16 or F32; quantizing from an already-quantized base fails with quantization is only supported for F16, BF16 and F32 models, and an unsupported level fails with unsupported quantization type listing the valid ones. Use it when importing an FP16 GGUF and you want a smaller deployment artifact without running llama.cpp separately. Two newer companions: --draft-quantize sets the level for speculative-decoding draft models, and create --experimental enables safetensors model creation.

The new model appears in your local registry:

NAME                   ID              SIZE      MODIFIED
sysadmin-bot:latest    ab1cd106e0ee    3.3 GB    Less than a second ago
gemma3:4b              a2af6cc3eb7f    3.3 GB    7 minutes ago

Now run it like any other model:

echo "How do I check disk space?" | ollama run sysadmin-bot

The system prompt kicks in and you get a focused response:

`df -h`  (Displays disk space in human-readable format)

Modelfile directives

DirectivePurposeExample
FROMBase model (required)FROM llama3.3
SYSTEMSystem promptSYSTEM "You are a helpful assistant"
PARAMETERSet model parametersPARAMETER temperature 0.7
TEMPLATEGo template for prompt formatTEMPLATE "{{ .Prompt }}"
ADAPTERPath to LoRA/QLoRA adapterADAPTER ./lora.gguf
MESSAGESeed conversation historyMESSAGE user "Hi"
LICENSELicense text for the modelLICENSE "MIT"
REQUIRESMinimum Ollama versionREQUIRES 0.32.0

Common PARAMETER values

ParameterDefaultDescription
temperature0.8Controls randomness. Lower values make output more deterministic
top_p0.9Nucleus sampling threshold
top_k40Limits token selection to top K candidates
num_ctx2048Context window size in tokens
repeat_penalty1.1Penalizes repeated tokens
seed0Random seed for reproducible output (0 = random)
stopmodel-specificStop sequences that end generation
num_predict-1Maximum tokens to generate (-1 = unlimited)

Environment Variables Reference

These environment variables configure the Ollama server. Set them in your systemd override file or export them before running ollama serve. The list below matches what ollama serve --help documents on the version tested for this page; memory-related ones like OLLAMA_KV_CACHE_TYPE interact directly with how much fits on your card, a topic the VRAM sizing guide covers with measured numbers per model size.

VariableDefaultDescription
OLLAMA_HOST127.0.0.1:11434Listen address and port
OLLAMA_MODELS~/.ollama/modelsModel storage directory (/usr/share/ollama/.ollama/models for the systemd service)
OLLAMA_KEEP_ALIVE5mHow long models stay loaded after last request
OLLAMA_CONTEXT_LENGTHauto (4k/32k/256k by VRAM)Default context length when the request does not set one
OLLAMA_NUM_PARALLEL1Maximum concurrent requests per model
OLLAMA_MAX_LOADED_MODELS3 per GPU (3 on CPU)Maximum models loaded simultaneously
OLLAMA_MAX_QUEUE512Maximum queued requests before rejecting (HTTP 503 after)
OLLAMA_MAX_TRANSFER_STREAMS4Parallel transfer streams for safetensors pulls/pushes
OLLAMA_ORIGINSlocalhost variantsAllowed CORS origins (comma-separated)
OLLAMA_NO_CLOUDfalseDisable cloud features (remote inference and web search)
OLLAMA_DEBUGfalseEnable debug logging (1=debug, 2=trace)
OLLAMA_FLASH_ATTENTIONfalseEnable flash attention
OLLAMA_KV_CACHE_TYPEf16KV cache quantization (f16, q8_0, q4_0). Halves or quarters KV memory
OLLAMA_GPU_OVERHEAD0Reserved VRAM per GPU in bytes
OLLAMA_IGPU_ENABLEfalseEnable integrated GPUs
OLLAMA_SCHED_SPREADfalseAlways shard a model across all GPUs (vs. preferring single-GPU placement)
OLLAMA_LLM_LIBRARYautoForce a specific backend, bypassing autodetection
OLLAMA_LOAD_TIMEOUT5mHow long to allow a model load to stall before giving up
OLLAMA_NOPRUNEfalseSkip pruning unused model blobs on startup
LLAMA_ARG_FITonllama.cpp automatic fit of unset memory options
LLAMA_ARG_FIT_TARGETautoTarget free VRAM margin per device for the fit logic (MiB)

Two client-side variables also exist for the REPL: OLLAMA_EDITOR (editor invoked by Ctrl+G) and OLLAMA_NOHISTORY (disable readline history). The LLAMA_ARG_* pair is new since the engine moved to llama.cpp and passes straight through to it.

Python SDK

The official Python client (ollama/ollama-python) wraps every endpoint above with typed responses. Install with pip install ollama. The five most common patterns are below; all snippets ran live against the test box. Note the think=False argument on the Qwen3 calls, which turns the reasoning trace off the same way --think=false does in the CLI.

import ollama

# 1. Generate (single-turn)
res = ollama.generate(model="qwen3:1.7b", prompt="Say hi in 5 words or less.", think=False)
print(res["response"])

# 2. Chat (multi-turn)
res = ollama.chat(
    model="qwen3:1.7b",
    messages=[{"role": "user", "content": "Reply with one word: yes"}],
    think=False,
)
print(res["message"]["content"], "eval_count:", res["eval_count"])

# 3. Streaming
for chunk in ollama.generate(model="qwen3:1.7b", prompt="List 3 colors:",
                             think=False, stream=True):
    print(chunk["response"], end="", flush=True)

# 4. Embeddings
res = ollama.embed(model="nomic-embed-text", input=["hello", "world"])
print(len(res["embeddings"]), "vectors of dim", len(res["embeddings"][0]))
# 2 vectors of dim 768

# 5. Tool calling
res = ollama.chat(
    model="qwen3:1.7b",
    messages=[{"role": "user", "content": "Weather in Nairobi?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"],
            },
        },
    }],
)
for call in (res["message"].tool_calls or []):
    print(call["function"]["name"], call["function"]["arguments"])
# get_weather {'city': 'Nairobi'}

For high-throughput services use ollama.AsyncClient (asyncio). For a remote server pass host="http://gpu-host:11434" to Client(...). The Node equivalent lives at ollama/ollama-js; for any other language, point an OpenAI SDK at http://localhost:11434/v1.

Useful One-Liners

Practical command combinations for scripting and daily use.

Check model disk usage

The systemd service stores models under the ollama user’s home:

du -sh /usr/share/ollama/.ollama/models/

With one 4B model, two small models and an embedder pulled:

5.7G	/usr/share/ollama/.ollama/models/

Pipe a file into a prompt

Summarize a log file, config, or any text file:

head -30 /var/log/apt/history.log | ollama run gemma3:4b "Summarize what packages were installed in one sentence"

The model reads the log and answers in plain language:

During the installation process, the following packages were installed: grub-pc, shim-signed, mokutil, grub-efi-amd64-signed, grub-efi-amd64-bin, and efibootmgr.

Batch inference from a file

Process multiple prompts from a text file, one per line:

while IFS= read -r prompt; do
  echo "=== $prompt ==="
  echo "$prompt" | ollama run gemma3:4b
  echo ""
done < prompts.txt

Quick benchmark: tokens per second

Run a standardized prompt with --verbose to measure generation speed:

ollama run gemma3:4b --verbose "Write a 50-word paragraph about Linux." 2>&1 | grep "eval rate"

Both prefill and generation rates print, and the gap between them matters as much as either number:

prompt eval rate:     35.00 tokens/s
eval rate:            9.00 tokens/s

If you want to see what those two rates look like on a large MoE model with real hardware on the line, the DeepSeek V4 Flash local hardware test measured both on a 128 GB box and found prompt processing, not generation, is the wall.

Check if Ollama API is reachable

The root endpoint answers with a plain string, which makes it a clean health check:

curl -s http://localhost:11434/

Returns Ollama is running if the server is up.

Pull multiple models in sequence

One loop keeps the downloads sequential so they don’t fight for bandwidth:

for model in gemma3:4b qwen3:1.7b nomic-embed-text; do
  echo "Pulling $model..."
  ollama pull "$model"
done

Export model list as JSON

Useful for backup scripts or inventory tracking:

curl -s http://localhost:11434/api/tags | python3 -c "
import sys, json
data = json.load(sys.stdin)
for m in data['models']:
    print(f\"{m['name']:30s} {m['details']['parameter_size']:>8s} {m['details']['quantization_level']}\")"

Sample output:

nomic-embed-text:latest            137M F16
deepseek-r1:1.5b                   1.8B Q4_K_M
qwen3:1.7b                         2.0B Q4_K_M
gemma3:4b                          4.3B Q4_K_M

Use Ollama with the OpenAI Python SDK

Point the official openai package at your local Ollama instance. No API key required.

pip install openai

Then in Python:

from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="unused")
response = client.chat.completions.create(
    model="gemma3:4b",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Quick Command Reference Table

All CLI commands at a glance, sorted by category.

CommandWhat it does
ollamaOpen the interactive agent TUI (chat, code, web search)
ollama pull MODELDownload a model from the registry
ollama list (alias ls)Show all local models
ollama psShow models loaded in memory
ollama show MODELDisplay model details (params, template, license)
ollama run MODELStart interactive chat or run one-shot prompt
ollama run MODEL --verboseRun with timing stats
ollama run MODEL --format jsonForce JSON output
ollama run MODEL --think=trueForce thinking mode on (R1, Qwen 3, gpt-oss; also high/medium/low)
ollama run MODEL --hidethinkingSuppress chain-of-thought from visible output
ollama run MODEL --keepalive 1hKeep the model loaded after the request
ollama run EMBED --dimensions NTruncate output embeddings (Matryoshka)
ollama run EMBED --truncate=falseError instead of truncating over-length embedding input
ollama stop MODELUnload model from memory
ollama cp SRC DSTCopy a model to a new name
ollama rm MODEL [MODEL...]Delete one or more models from disk
ollama create NAME -f FILEBuild a custom model from a Modelfile
ollama create NAME -f FILE -q q4_K_MBuild and quantize in one step (F16+ source; q4_K_S, q4_K_M, q8_0)
ollama push NAMESPACE/MODELPush a model to the registry (requires signin)
ollama signin / ollama signoutAuthenticate with ollama.com
ollama launch [integration]Open the launch menu or hand off to a coding agent
ollama launch NAME --restoreRestore an integration to its default profile
ollama serve (alias start)Start the server manually
ollama --versionPrint Ollama version

Bookmark this page; it gets re-tested against each significant Ollama release. If a command here behaves differently on your version, check ollama --version first and the release notes second.

Keep reading

Claude Code Cheat Sheet – Commands, Shortcuts, Tips AI Claude Code Cheat Sheet – Commands, Shortcuts, Tips Ollama Models Cheat Sheet 2026 (gpt-oss, Qwen3-Coder, DeepSeek) AI Ollama Models Cheat Sheet 2026 (gpt-oss, Qwen3-Coder, DeepSeek) OpenCode CLI Cheat Sheet – Commands and Workflows AI OpenCode CLI Cheat Sheet – Commands and Workflows Best Machine Learning and Statistical Learning Books for 2026 AI Best Machine Learning and Statistical Learning Books for 2026 Claude Fable 5.1 Released: Benchmarks, Pricing, and API Changes AI Claude Fable 5.1 Released: Benchmarks, Pricing, and API Changes Best PoE Cameras for a Frigate NVR AI Best PoE Cameras for a Frigate NVR

Leave a Comment

Press ESC to close