Web Asset House Guides
Local AI

Ollama API Usage Metrics and Errors: Measuring Tokens per Second and Handling Failures

By Web Asset House Studio ·

Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.

How we wrote this: A summary of Ollama's official API documentation pages on usage metrics, errors and streaming (linked below), checked October 29, 2026. The example numbers come from Ollama's own example response; we don't publish speed figures for any model or machine, since they depend entirely on your hardware.

When you call Ollama's local API, the response carries more than the answer: it includes timing and token counts you can use to measure speed, see whether a model had to load, and check how much of your prompt was cached. And when something goes wrong, Ollama returns errors in a predictable format. This guide covers both. If you're new to the API, start with our Ollama local API basics.

The usage fields

Ollama's usage page lists these metrics:

Field What it measures
total_duration How long the whole response took to generate
load_duration How long the model took to load
prompt_eval_count How many input tokens were in the prompt
prompt_eval_cached_count How many prompt tokens were read from the cache
prompt_eval_duration How long it took to evaluate the uncached prompt tokens
eval_count How many output tokens were generated
eval_duration How long it took to generate the output tokens

The detail that trips people up: all timing values are in nanoseconds. Divide by 1,000,000,000 to get seconds.

Ollama's example response

From the usage page, a non-streaming call to /api/generate:

{
  "model": "gemma4",
  "response": "Hello! How can I help you today?",
  "done": true,
  "done_reason": "stop",
  "total_duration": 174560334,
  "load_duration": 101397084,
  "prompt_eval_count": 11,
  "prompt_eval_cached_count": 8,
  "prompt_eval_duration": 13074791,
  "eval_count": 18,
  "eval_duration": 52479709
}

Turning the numbers into useful figures

This is simple arithmetic on the documented fields, using the example above:

A few practical readings:

Here's a short Python example that reads the documented fields from a non-streaming /api/generate response (it uses the standard requests package and assumes Ollama is running locally with the model pulled):

import requests

r = requests.post("http://localhost:11434/api/generate",
                  json={"model": "gemma4", "prompt": "Say hello.", "stream": False})
d = r.json()
tps = d["eval_count"] / (d["eval_duration"] / 1e9)
print(f"{d['eval_count']} tokens at {tps:.1f} tokens/s; load {d['load_duration']/1e9:.2f}s")

Metrics in streaming responses

Ollama's docs say that for streaming endpoints, the usage fields come in the final chunk, the one where done is true. So read the last object in the stream to get them. Our streaming responses guide covers how streaming chunks are structured.

HTTP status codes

Ollama's errors page lists the common status codes:

Code Meaning, per Ollama
200 Success
400 Bad Request (missing parameters, invalid JSON, etc.)
404 Not Found (for example, the model doesn't exist)
429 Too Many Requests (for example, a rate limit was exceeded)
500 Internal Server Error
502 Bad Gateway (for example, a cloud model can't be reached)

A 404 on a local call most often means the model name is wrong or the model hasn't been pulled; ollama list shows what's installed.

The error format

Errors come back as JSON with the message in an error property:

{ "error": "the model failed to generate a response" }

Errors in the middle of a stream

This is the case to code for. Ollama says if an error happens mid-stream, it arrives as an object with an error property in the application/x-ndjson stream, and because the response already started, the HTTP status code isn't changed. In other words, a stream can start with 200 OK, deliver some tokens, and then end with:

{"error":"an error was encountered while running the model"}

So when you process a stream, check every line for an error key rather than relying on the status code alone. If errors keep happening, the server logs usually explain why; see our Ollama troubleshooting guide.

Sources

← All Local AI guides · All guides