Tutorial · Ollama · API

Use the Ollama API Locally

Turn Ollama from an interactive CLI into a local model service that your scripts and applications can call over HTTP.

UPDATED SEP 25, 2026 · INTERMEDIATE

What you are building

Ollama can act as a local HTTP model service. Your terminal, script or application becomes the client; Ollama owns the local runtime; the selected model performs inference.

PowerShell / application
          ↓ HTTP
http://localhost:11434/api
          ↓
        Ollama
          ↓
     local model

This tutorial uses PowerShell because it makes every request visible. The same API can later sit behind your own application.

1. Check the local server without generating

Ask Ollama for the local model list:

PowerShell
Invoke-RestMethod -Uri http://localhost:11434/api/tags

If this request succeeds, the local HTTP service is reachable. If the model list is empty, that is a model-management issue rather than proof that the API itself is broken.

2. Send a generation request

Replace MODEL_NAME with a model already present in ollama ls:

PowerShell
$body = @{
  model  = "MODEL_NAME"
  prompt = "Explain local inference in two sentences."
  stream = $false
} | ConvertTo-Json

$result = Invoke-RestMethod -Method Post -Uri http://localhost:11434/api/generate -ContentType "application/json" -Body $body

$result.response

Setting stream to false makes this first diagnostic easier to inspect because PowerShell receives one completed structured response rather than a stream of incremental objects.

3. Inspect the structured response

Do not limit debugging to the generated text. Inspect the returned object:

PowerShell
$result | Format-List *

Runtime versions and endpoints can expose metadata useful for measurement. When E—DOCEO runs a Lab, we record the fields actually returned by the tested runtime rather than assuming every version reports identical metadata.

4. Keep comparison tests reproducible

For casual use, sampling settings are a product choice. For a benchmark, configuration is part of the experiment. Record at minimum the model identifier, runtime version, prompt, context configuration and any sampling controls you explicitly change.

E—DOCEO's existing local-model Labs use fixed prompts and record the runtime environment. That does not make generative output perfectly identical across runs, but it makes the comparison auditable.

LAB RULE
Do not compare two models while silently changing the prompt, context, runtime version or measurement method. A benchmark is a configuration, not just a model name.

Troubleshooting

If /api/tags fails, first verify that Ollama itself is running. If /api/tags works but generation fails, check the exact installed model name with ollama ls and test that model interactively with ollama run MODEL_NAME.

If generation works but is unexpectedly slow, inspect ollama ps and then use the E—DOCEO guides for VRAM, context length and model offloading. API connectivity and hardware placement are separate layers.

Next steps

You now have the minimum architecture needed for a local application: an HTTP client and a local model service. Continue with Ollama model management, or inspect the DOCEO LAB to see how we record repeatable local-inference measurements.

Sources