Run models locally
Call the local chat API
Send a complete chat request with curl and inspect content, token counts, loading time, and generation time in the response.
Ollama serves an HTTP API on localhost:11434 by default.
Send one non-streaming chat request:
curl http://localhost:11434/api/chat -d '{
"model": "gemma3:1b",
"messages": [
{"role": "user", "content": "Explain local inference in one sentence."}
],
"stream": false
}'
The generated text is inside message.content. You will also see fields such as done, done_reason, and timing counters on the same JSON object.
The final response also includes measurements such as load_duration, prompt_eval_count, prompt_eval_duration, eval_count, and eval_duration.
Durations use nanoseconds. Generated tokens per second can be estimated with:
eval_count / (eval_duration / 1,000,000,000)
If eval_count is 20 and eval_duration is 2,000,000,000 nanoseconds, that is about 10 tokens per second for that request on your hardware.
The first request may include model loading. A later request can be faster while the model remains in memory. Compare two back-to-back calls when you benchmark. The first number includes load time unless you warm the model deliberately.
Do not expose the Ollama port directly to an untrusted network. A local service normally has no reason to accept requests from every device or website. Bind to localhost and keep authentication in your application layer if remote access is ever required.
My advice is to log prompt_eval_count and eval_count during development. They explain slow responses better than guessing. A huge prompt shows up in prompt_eval_count even when the answer is short.
Save one full JSON response the first time you integrate. That file becomes the reference when you add streaming or structured output later.
Pipe the response through a formatter when your terminal wraps JSON:
curl -s http://localhost:11434/api/chat -d '{
"model": "gemma3:1b",
"messages": [{"role": "user", "content": "Say hello in three words."}],
"stream": false
}' | python3 -m json.tool
You should see "done": true and a short string inside message.content.
Try this now: run the curl command and paste message.content and the token counts into your notes. That snapshot becomes your baseline when you change models later.
Lesson completed