Web Asset House Guides
Local AI

Using Ollama's Local API: Call Your Own Model from Scripts and Apps

By Web Asset House Studio ·

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:

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:

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:

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.

Sources

← All guides