Using Ollama's Local API: Call Your Own Model from Scripts and Apps
Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.
How we wrote this: A summary of Ollama's official API documentation and FAQ (linked below). We have not benchmarked any hardware or model. Model names in the examples are placeholders, so use one you've downloaded.
Once Ollama is running on your computer, it's more than a chat window. It also runs a small web server that your own scripts, spreadsheets and apps can talk to. This guide covers the basics. If you haven't installed Ollama yet, start with our beginner walkthrough.
Where the API lives
Per the Ollama API docs, a local Ollama server answers at:
| Style | Local base URL |
|---|---|
| Ollama's native API | http://localhost:11434/api |
| OpenAI-compatible API | http://localhost:11434/v1 |
Local requests don't need an API key. Ollama also offers a cloud service at ollama.com that does need one. This guide covers only the local server, where requests stay on your machine.
The FAQ says Ollama "binds 127.0.0.1 port 11434 by default". In other words, only programs on the same computer can connect.
A first request
The chat endpoint docs show a request like this (swap in a model you've pulled):
curl http://localhost:11434/api/chat -d '{
"model": "your-model",
"messages": [{"role": "user", "content": "Why is the sky blue?"}],
"stream": false
}'
The reply is JSON. The answer is in message.content, plus timing fields such as total_duration and eval_count (tokens generated). Two documented details:
streamdefaults to true. Without"stream": false, the answer arrives in pieces as it's generated, which suits chat interfaces.formatcan bejsonor a JSON schema when you need structured output for a script.
Reuse code written for OpenAI
Ollama's OpenAI compatibility page says it supports a subset of the OpenAI API. Official OpenAI client libraries work if you point them at http://localhost:11434/v1/. The client still requires an API key value, but Ollama ignores it, and the docs' examples use the placeholder ollama. That makes it easy to try an existing tool against a local model without rewriting it.
Keep a model loaded, or free the memory
The FAQ explains that models stay in memory for 5 minutes by default after a request, so follow-up requests are fast. You can change this per request with keep_alive:
"keep_alive": -1keeps the model loaded."keep_alive": 0unloads it right after responding.- The
ollama stopcommand unloads a model immediately.
On a laptop with limited RAM, unloading matters: a loaded model holds its memory even while idle. Private AI Computer's memory calculator estimates how much a model needs.
Opening it to your network (carefully)
The FAQ shows how to change the bind address with the OLLAMA_HOST environment variable, for example to 0.0.0.0:11434, so other devices on your network can connect. The local API has no password, so anyone who can reach that port can use your models. If you do this:
- Do it only on a network you trust, and never forward the port from your router to the internet.
- If you need remote access, the FAQ describes putting Ollama behind a proxy server. Add authentication there.
- Our home office Wi-Fi guide covers the router settings that keep the rest of your network safe.
A friendlier front end
If you want a ChatGPT-style browser interface on top of the same API, see our guide to Open WebUI for local models.