Docs

Ollama's OpenAI-compatible API

Ollama serves an OpenAI-compatible API for local models. Here's how to call it with the OpenAI SDK — and how the same code reaches hosted Claude, Gemini and GPT by changing only base_url and model.

Bu doküman İngilizce'dir. Türkçe hızlı başlangıç kılavuzu için:Türkçe rehber — Türkiye'den Claude API

Ollama runs open models on your own machine and exposes them through an OpenAI-compatible API at http://localhost:11434/v1. Because the wire format matches OpenAI, the official OpenAI SDK works against Ollama unchanged — and the same code reaches hosted frontier models by changing only the base URL.

TL;DR — Ollama's OpenAI API is at http://localhost:11434/v1. Set the OpenAI client's base_url there and any placeholder api_key. To use hosted Claude/Gemini/GPT instead, change base_url to https://api.kunavo.com/v1 and the model slug — nothing else.

What Ollama's OpenAI-compatible API is

Ollama is a separate open-source project for running models like Llama, Qwen and Mistral locally. Alongside its native API it ships an OpenAI-compatible surface, so tools built for OpenAI work without a rewrite. It implements the endpoints most apps use:

EndpointPurpose
POST /v1/chat/completionsChat — the endpoint most apps use
POST /v1/completionsLegacy text completions
POST /v1/embeddingsEmbeddings for local models
GET /v1/modelsList locally pulled models

It covers chat, completions and embeddings (plus vision input on multimodal local models). It does not generate images, video or audio.

Call Ollama with the OpenAI SDK

Point base_url at http://localhost:11434/v1. The SDK requires an api_key, but local Ollama ignores its value — pass any string. Set model to a model you've pulled (e.g. ollama pull llama3.2).

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1",  # Ollama's OpenAI-compatible API
    api_key="ollama",  # required by the SDK, ignored by local Ollama
)

resp = client.chat.completions.create(
    model="llama3.2",
    messages=[{"role": "user", "content": "Explain quicksort in one paragraph."}],
)
print(resp.choices[0].message.content)

Or with curl:

curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3.2",
    "messages": [{"role": "user", "content": "Hello, Ollama"}]
  }'

The same code, hosted frontier models

Ollama is ideal for offline development and privacy-sensitive work, but local models trail the frontier on hard reasoning, coding and long context. Because Kunavo is also OpenAI-compatible, moving a call to a hosted model is a two-line change — base_url and the model slug:

from openai import OpenAI

client = OpenAI(
    base_url="https://api.kunavo.com/v1",  # only this line changes
    api_key="sk-kunavo-...",               # a real key now
)

resp = client.chat.completions.create(
    model="claude-sonnet-4-6",  # a hosted frontier model
    messages=[{"role": "user", "content": "Explain quicksort in one paragraph."}],
)
print(resp.choices[0].message.content)
Ollama (local)Kunavo (hosted)
Base URLlocalhost:11434/v1api.kunavo.com/v1
Runs onYour machineManaged API
ModelsLocal open modelsClaude, Gemini, GPT + 200+
ModalitiesText + embeddingsText, image, video, audio
CostYour hardware / electricityPer token, 30–70% under list
Best forOffline dev, privacyProduction frontier quality
One key on Kunavo reaches every hosted model, billed once via Stripe — see the quickstart for your first call.

Switch by environment

A common pattern is Ollama for local dev and hosted models in production, selected by an environment variable. The client and request code are identical — only base_url and the model differ:

import os
from openai import OpenAI

# One client, switched by environment. Local for dev, hosted for prod.
if os.getenv("APP_ENV") == "production":
    client = OpenAI(base_url="https://api.kunavo.com/v1",
                    api_key=os.environ["KUNAVO_API_KEY"])
    MODEL = "gemini-2-5-flash"
else:
    client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
    MODEL = "llama3.2"

resp = client.chat.completions.create(
    model=MODEL,
    messages=[{"role": "user", "content": "ping"}],
)
print(resp.choices[0].message.content)

FAQ

Does Ollama have an OpenAI-compatible API?

Yes. Ollama exposes an OpenAI-compatible REST API at http://localhost:11434/v1 with /chat/completions, /completions, /embeddings and /models. Point the official OpenAI SDK at that base_url, pass any string as the api_key (Ollama ignores it locally), and set model to a pulled model like llama3.2. The request and response shapes match OpenAI.

What base URL does Ollama's OpenAI API use?

http://localhost:11434/v1 by default. Set the OpenAI client base_url to that value. If Ollama runs on another host or port, substitute it — the /v1 suffix stays.

How do I switch from Ollama to a hosted model?

Because both are OpenAI-compatible, you change only base_url and model. Swap http://localhost:11434/v1 for https://api.kunavo.com/v1, use a real sk-kunavo- key, and set model to a hosted slug like claude-sonnet-4-6 or gemini-2-5-flash. No other code changes.

Does Ollama's OpenAI API support images or video?

Ollama's OpenAI-compatible surface covers chat, completions and embeddings, plus vision input on multimodal local models. It does not generate images, video or audio. For hosted image, video and audio generation on the same OpenAI-style API, use Kunavo's /v1/images, /v1/video and /v1/audio endpoints.

Where to go next