To call a local model from your own code, send a request to the Ollama server running on your own computer at http://localhost:11434/api/chat, with a downloaded model and no API key. Ollama’s API introduction says local requests do not need an API key, and gives the chat endpoint and the OpenAI-compatible address http://localhost:11434/v1. Your code talks to your own machine, not to a cloud service.
The request, copied from Ollama’s own examples
Ollama’s README shows the chat request as a curl command. It uses the model llama3.2 and the sample prompt “why is the sky blue?”:
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [
{ "role": "user", "content": "why is the sky blue?" }
]
}'
The API introduction adds the rule that matters most for beginners: “For local inference, use http://localhost:11434/api/chat with a downloaded model and omit the authorization header.” If a code sample you find online includes an authorization header or an API key, that sample is written for a remote service, not for a local Ollama server.
Try it: one request, one reply
First download the model, then send the request above from your terminal. Use the practice prompt exactly as shown, so you can compare your reply with the shape below.
| Step | What you do | What you should see |
|---|---|---|
| 1. Download | ollama pull llama3.2 |
The model downloads |
| 2. Send | Run the curl command above | A reply comes back from localhost:11434 |
| 3. Check | Read the reply text | An answer to “why is the sky blue?” |
Expected result. We checked the Ollama API introduction and README. We did not run the curl request on this machine.
Limits
The server listens on your own computer by default — Ollama’s FAQ says it binds 127.0.0.1 on port 11434 — so the request above works only on the machine where Ollama runs, unless you change OLLAMA_HOST. The reply is generated by the model you downloaded, so a small model can give a short or imperfect answer; that is a property of the model, not of the API call. We did not run the request, so no reply text here is a recorded result.
