EN ▾
Get API key

Ollama API vs OpenAI API: Endpoints and Code

The ollama api vs openai api question comes down to two request formats and two places to run a model. Ollama has its own native API and also an OpenAI-compatible layer, so moving to a hosted OpenAI-style endpoint can be a change of base URL and key.

Updated

Desktop machine and cloud server linked by two light bridges carrying identical message envelopes
Chat window connected to both a local computer and a cloud server by glowing cables

No card needed. After sign-up, claim $0.50 of free test credit with one click (once per person).

Get API key

Key points

  • Ollama has native routes under /api and an OpenAI-compatible layer under /v1; clients written for the OpenAI SDK usually work with either.
  • Native Ollama streams newline-delimited JSON, while the OpenAI format streams server-sent events.
  • Moving from local to hosted means changing the base URL, key and model name, not your code.
  • Local keeps data on your machine; hosted removes the hardware work and adds a per-token bill.

The short version

Both ask you to POST a list of messages and get text back. The difference is the shape of the request, where the server lives and who pays for the GPU. Ollama runs models on your own computer and listens on port 11434. The OpenAI API is a hosted service with its own paid models. In the ollama api vs openai api comparison people often miss a third thing: Ollama also exposes OpenAI-compatible routes, so the two formats overlap.

That overlap is what makes migration cheap. If your app already uses the OpenAI SDK, you can point it at a local Ollama today and at a hosted OpenAI-compatible URL tomorrow. The hosted endpoint on this site is one of those. It serves a single model, uncensored, at https://api.ollamansfw.com/v1, and it is not an official product of OpenAI, Meta or any other lab.

Endpoint-by-endpoint differences

TaskOllama nativeOpenAI-style
ChatPOST /api/chatPOST /v1/chat/completions
Single promptPOST /api/generatePOST /v1/responses or chat completions
List modelsGET /api/tagsGET /v1/models
AuthNone by defaultAuthorization: Bearer key
StreamingNewline-delimited JSONServer-sent events, ending in a done marker
Model nameWhatever you pulled, such as llama3Whatever the provider lists

Ollama also serves /v1/chat/completions and /v1/models on the same port, which is what lets OpenAI clients work against it. Its default for native calls is to stream, so set stream: false when you want a single JSON reply.

The hosted endpoint implements POST /v1/chat/completions, POST /v1/responses and GET /v1/models, plus balance checks at GET /v1/balance. See the API docs for the full list.

The same request, three ways

Native Ollama from Python:

import requests

r = requests.post(
    "http://localhost:11434/api/chat",
    json={
        "model": "llama3",
        "messages": [{"role": "user", "content": "Say hello in five words."}],
        "stream": False,
    },
)
print(r.json()["message"]["content"])

The OpenAI SDK, with local and hosted settings side by side. Only the commented line changes:

from openai import OpenAI

# Local Ollama through its OpenAI-compatible layer:
# client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

# Hosted endpoint, same code from here on:
client = OpenAI(base_url="https://api.ollamansfw.com/v1", api_key="YOUR_KEY")

resp = client.chat.completions.create(
    model="uncensored",   # local would be e.g. "llama3"
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(resp.choices[0].message.content)

And curl against the hosted endpoint with streaming on:

curl https://api.ollamansfw.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Hello"}],"stream":true}'

Parsing differs on the native side: each streamed line is a JSON object with message.content, and the last has done: true. In the OpenAI format each event starts with data: , carries a choices[0].delta.content piece, and the stream ends with [DONE]. Use the SDK and you never see either.

Where each one makes sense

Local Ollama is the right choice when privacy is the top concern, when you have a GPU with enough memory for the model you want, or when you tinker with many models. Nothing leaves your machine and there is no per-token bill. Costs show up as hardware, power and your time. Our guide to using Ollama with a GUI covers the friendly side of that route.

A hosted OpenAI-compatible endpoint fits better when you lack the hardware, need many parallel requests, run a bot or service for other people, or want a stable URL that does not depend on your laptop being awake. A full key allows 8 concurrent requests and 300 requests per minute. The context window is 100,000 tokens, which is more than many local setups can hold in memory.

Plenty of people use both: local for experiments, hosted for anything that has to stay up. If you are weighing other local tools, read Ollama software alternatives.

Migrating from local Ollama to hosted

  1. Switch to the OpenAI format first. If your code calls /api/chat, move it to the OpenAI SDK pointing at Ollama's /v1 route. Confirm it still works locally.
  2. Get a key. Sign up and claim the $0.50 trial on the API key page. It needs no payment and lasts 7 days.
  3. Change three values. Base URL to https://api.ollamansfw.com/v1, key to yours, model to uncensored.
  4. Check parameters. Temperature, top_p, stop, seed and the penalties are passed through. Local-only options such as Ollama's num_ctx or keep_alive do not apply; the window is fixed at 100,000 tokens.
  5. Add retry logic. The hosted API returns 429 with rate_limited or concurrency past a limit, and 429 with Retry-After: 5 during temporary overload. Local servers rarely do that, so existing code may not handle it.

If something fails after the switch, the article on common Ollama API mistakes covers frequent causes such as wrong ports and missing model names.

What hosted costs, and what it will not do

Billing is pay as you go from prepaid credit: $0.15 per 1M input tokens and $0.50 per 1M output tokens. A chat turn with 1,000 input and 400 output tokens costs $0.00015 + $0.0002 = $0.00035, so $20 covers about 57,000 such turns. Failed or refused requests are not charged and credit never expires. Top-ups run from $20 to $500 with bonuses of +5% from $50, +10% from $100 and +15% from $200. Payment is by crypto only (USDT on TRC20 or USDC on Base). More on the pricing page.

Limits to know: text only, so no embeddings, image generation or fine-tuning. If you rely on local embeddings, keep those local. The model is tuned to answer without content refusals for lawful adult use. Sexual content involving minors is never allowed. Prompts are not used for training.

Questions and answers

Is the Ollama API compatible with the OpenAI API?

Partly. Ollama has native routes under /api and also serves OpenAI-style routes such as /v1/chat/completions, so OpenAI SDK clients can talk to it.

What do I change to move from local Ollama to a hosted endpoint?

The base URL, the API key and the model name. If your code already uses the OpenAI SDK, nothing else needs to change.

Does the hosted API support embeddings like Ollama?

No. It is text generation only: chat completions and responses, with no embeddings, images or fine-tuning.

Is Ollama free?

The software is free to download and run. You still pay for hardware and power, while a hosted API charges per token.