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.
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)
The first request may include model loading. A later request can be faster while the model remains in memory.
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.
Lesson completed