Ollama’s local API listens on http://localhost:11434. The /api/generate endpoint takes a model and a prompt and returns generated text, which is the simplest way to call a local model from a script.
What you need
- Ollama running with a model pulled, for example llama3.2
- curl installed
- A terminal on the same machine
Step 1: Send the request
Run: curl http://localhost:11434/api/generate -d ‘{model: llama3.2, prompt: Why is the sky blue?, stream: false}’. Setting stream to false returns one complete JSON object instead of a stream of chunks.
Step 2: Read the response
The reply is JSON with a response field holding the generated text, plus timing fields such as eval_count and eval_duration. Divide eval_count by eval_duration and multiply by 1,000,000,000 to get tokens per second.
Step 3: Confirm the server is up first if it fails
If curl reports connection refused, check that Ollama is running and listening on port 11434. On Linux, systemctl status ollama shows the service state.
Worked example: one generate call
The table below is a synthetic example. The endpoint, the stream flag, and the timing fields come from the Ollama API docs; the prompt and reply are illustrative.
| Part | Value | Note |
|---|---|---|
| Endpoint | POST /api/generate | Localhost port 11434 |
| Body | model llama3.2, stream false | One JSON reply |
| Reply | response field | Generated text |
Expected result (UNTESTED). curl returns HTTP 200 with a JSON object whose response field holds the answer to the prompt. This check was not run live; the endpoint and fields come from the cited API docs.
Limits
- The model must be pulled first; an unknown model returns an error.
- The API has no authentication on localhost, so do not expose port 11434 beyond the machine.
- Without stream false, the reply arrives as a stream of JSON chunks.
- Generation speed depends on GPU offload; check ollama ps if it is slow.
