Calling the Local HTTP API
An API you can call from the terminal
An API is a defined way for programs to talk to each other. Ollama listens only on this machine at Internet Protocol (IP) address 127.0.0.1 and port 11434. Send it a JSON request with curl:
curl -s http://127.0.0.1:11434/api/generate \
-H 'Content-Type: application/json' \
-d '{"model":"qwen2.5:0.5b","prompt":"Reply READY","stream":false}' | jq -r .response
stream:false waits and returns one complete JSON document. Streaming returns small newline-separated JSON pieces as they are generated. Streaming feels faster in a chat screen, but your code must read and join the pieces one at a time.
Tip:curl -fmakes an HTTP error produce a failing exit code.jqis a tool for reading JSON;jq -ealso fails when the expected condition is false. Both make automation notice errors instead of trusting attractive output.