Tutorial 9: Setting up a Local API Server

By Jakub RusinowskiLast updated 7 min readIntermediate

Turn your local machine into an AI backend for other apps.

Ollama API

Ollama runs a server by default on port 11434. Since version 0.35 the same server also answers /v1/systemone for decision models: build a request, follow the setup guide, and see what a 400, 404 or 413 means.

bash
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.1",
  "prompt": "Why is the sky blue?"
}'

OpenAI Compatible Endpoint

Many apps expect the OpenAI API format. Ollama provides this too! Endpoint: http://localhost:11434/v1/chat/completions

Python Example

python
from openai import OpenAI

client = OpenAI(
    base_url='http://localhost:11434/v1',
    api_key='ollama', # required but unused
)

response = client.chat.completions.create(
    model="llama3.1",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Going Further