Key points
- Ollama serves local models; it does not forward requests to a hosted API
- Both speak the OpenAI chat completions format, so the same SDK code works for either
- Switch with three values: base URL, API key and model name
- Hosted base URL here: https://api.wanapi.cc/v1 with the model uncensored
How the two fit together
The phrase openai compatible api for ollama can mean two different things, so it helps to separate them. The first meaning is Ollama's own compatibility layer: it runs open models on your computer and offers an endpoint at http://localhost:11434/v1 that accepts OpenAI-style requests. The second meaning is a hosted service that also speaks that protocol, so tools built for Ollama or for OpenAI can use it as well.
These two are siblings, not a chain. Ollama does not act as a proxy that passes your prompts on to a remote API. It loads models you have pulled and runs them locally. What you can do is write your code against the OpenAI-style interface once, then point it at Ollama when you want local inference and at a hosted base URL when you want a larger model without the hardware. This article shows the pattern with the endpoint on this site: https://api.wanapi.cc/v1, model uncensored.
The three values that change
Any OpenAI-style client needs three settings. Moving between local and hosted is a matter of swapping them.
| Setting | Local Ollama | Hosted here |
|---|---|---|
| Base URL | http://localhost:11434/v1 | https://api.wanapi.cc/v1 |
| API key | Any placeholder string (Ollama ignores it) | Your real key, sent as a Bearer token |
| Model | A model you pulled, for example the name shown by ollama list | uncensored |
The endpoints you will use are the same on both sides: POST /v1/chat/completions for conversations and GET /v1/models to list what is available. The hosted service lists one model, uncensored. Your local list depends on what you have pulled.
One safety habit: keep the real key out of any file that also holds the localhost configuration. A placeholder for local use and a real key for hosted use should live in separate environment variables, so the real key is never sent to the wrong place.
Python: one function, two backends
The cleanest approach is a small config switch driven by environment variables. The rest of your program does not need to know which backend it is talking to.
import os
from openai import OpenAI
BACKEND = os.getenv("LLM_BACKEND", "local")
if BACKEND == "local":
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
MODEL = os.getenv("LOCAL_MODEL", "llama3")
else:
client = OpenAI(
base_url="https://api.wanapi.cc/v1",
api_key=os.environ["WANAPI_KEY"],
)
MODEL = "uncensored"
def chat(prompt):
resp = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
)
return resp.choices[0].message.content
print(chat("Give me three names for a harbour town in a fantasy story."))
The local model name llama3 in the example is only a stand-in; use whatever ollama list shows on your machine. Run it with LLM_BACKEND=hosted WANAPI_KEY=... python app.py to hit the hosted endpoint, and without those variables to stay local. Your prompt-building code, retries and logging stay identical.
Node and curl
The same switch works in JavaScript with the official OpenAI package.
import OpenAI from "openai";
const hosted = process.env.LLM_BACKEND === "hosted";
const client = new OpenAI(
hosted
? { baseURL: "https://api.wanapi.cc/v1", apiKey: process.env.WANAPI_KEY }
: { baseURL: "http://localhost:11434/v1", apiKey: "ollama" }
);
const model = hosted ? "uncensored" : process.env.LOCAL_MODEL || "llama3";
const stream = await client.chat.completions.create({
model,
messages: [{ role: "user", content: "Describe a rainy market in two sentences." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
And for a quick check from a terminal, curl against the hosted side, then the model list:
curl https://api.wanapi.cc/v1/chat/completions -H "Authorization: Bearer $WANAPI_KEY" -H "Content-Type: application/json" -d '{"model":"uncensored","messages":[{"role":"user","content":"Reply with the word ready."}],"max_tokens":10}'
curl https://api.wanapi.cc/v1/models -H "Authorization: Bearer $WANAPI_KEY"
Streaming uses server-sent events with stream: true, and usage is reported at the end of the stream. Tool calling and JSON mode (response_format with json_object) are available on the hosted side. On the local side, support for those features depends on the model you pulled and your Ollama version, so test before relying on them.
Front ends that take both
Many chat interfaces and developer tools let you add an OpenAI-compatible connection next to a local Ollama connection. Open WebUI is one example: you can add an OpenAI-style API with a URL and a key, and then pick models from either source in the same window. The same idea holds for roleplay and writing front ends such as SillyTavern, which let you add an OpenAI-compatible endpoint.
The steps are nearly always the same:
- Open the tool's connection or API settings and choose the OpenAI-compatible option.
- Enter
https://api.wanapi.cc/v1as the base URL. - Paste your API key.
- Refresh the model list, or type
uncensoredby hand if the list stays empty. - Send a short test message before loading a long conversation.
If a tool asks for the full path, the chat route is https://api.wanapi.cc/v1/chat/completions. Leave a trailing slash off the base URL unless the tool insists on it. Get a key on the API key page.
Local or hosted: how to choose
Neither side is better in every case. Decide on the facts of your project.
Choose local Ollama when
- Your hardware can run a model you are happy with, and you do not mind its speed.
- You want text that never leaves your machine, with nothing to pay per token.
- You work offline.
Choose a hosted endpoint when
- You do not have a GPU, or the model you want does not fit in memory.
- You need a 100,000-token context window without sizing RAM for it. On a local setup, the usable context depends on the model and your memory.
- You need several clients to use the same service at once. A full key allows 8 concurrent requests and 300 per minute.
The hosted model is tuned to answer without content refusals for lawful adult use, with a hard limit of no sexual content involving minors. Prompts are not used for training. It handles text only, with no images, audio, embeddings or fine-tuning. If you use Ollama for any of those, keep using it for them.
Cost and the trial
Local inference costs electricity and hardware time. The hosted side charges $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit that never expires. A typical chat turn with 1,500 input tokens and 300 output tokens costs $0.000225 plus $0.00015, which is $0.000375.
New users can claim $0.50 of trial credit with one click on the API key page, with no card, valid for 7 days. That covers about 1,333 such turns, enough to see whether the hosted model suits your project. Top-ups for continued use run from $20 to $500; see the pricing page for bonuses. For details on headers and error codes, the quickstart is the reference.
Common mistakes
- Wrong model name. A local model name sent to the hosted API fails, and
uncensoredsent to Ollama fails too. Switch the model along with the URL. - Missing
/v1. Both base URLs end in/v1. Leaving it off gives a 404. - Real key in the wrong place. Never put the hosted key in a config that points at a different host.
- Too many parallel calls. A local server may queue them; the hosted side returns 429 above the limits, with
rate_limitedorconcurrencyas the code. Cap your workers at 8 on a full key. - Expecting identical output. Different models answer differently. Compare on your own prompts.
Testing that both endpoints behave the same
Before you rely on a switch between local and hosted, run a short check that confirms both backends answer in the shape your code expects. List the models, send one plain message, and send one streamed message.
def check(client, model):
names = [m.id for m in client.models.list().data]
print("models:", names[:5])
r = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Reply with one word."}],
max_tokens=10,
)
print("plain:", r.choices[0].message.content)
s = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Count to three."}],
stream=True,
)
print("stream:", "".join((c.choices[0].delta.content or "") for c in s if c.choices))
check(client, MODEL) # MODEL is "uncensored" on the hosted backend
Call it once per backend at startup in development. If the local call fails with a model-not-found error, the name does not match anything you pulled. If the hosted call returns a 401, the key is missing or wrong. Both mistakes show up in seconds with this script, long before a user finds them.
Keep the output of this check for later. If a front end such as Open WebUI shows an empty model list after you add the hosted connection, the models call here tells you whether the issue is the key, the base URL or the tool. A 200 response listing uncensored proves the endpoint and key are fine, and the remaining problem is in the tool's settings, often a trailing slash or a missing /v1.
It also helps to keep two named profiles in your tool, one for each backend, rather than editing a single connection back and forth. Name them plainly, such as local and hosted, so a stray click does not send a private draft to the wrong place. When you use the hosted profile, remember that a full key allows 8 requests at once; the local profile has whatever limit your own machine imposes.
