EN ▾
Get API key

Ollama Switch: Move Your Client to a Hosted API

An ollama switch is a small change when your client already speaks the OpenAI chat format: new base URL, new key, new model name. This guide walks through the change, the checks and the traps.

Updated

Railway switch sending data packets from a local box to a cloud server, for moving from Ollama to a hosted API

Key points

  • Switching means changing three values: base URL, API key and model ID.
  • Keep your local Ollama setup as a fallback behind an environment variable.
  • Embeddings and model-pulling have no equivalent on the hosted side.
  • Test with a models call, then a plain request, then streaming, then tools.

Before you change anything

Spend five minutes writing down how your app talks to Ollama today. There are two common patterns. In the first, the app uses Ollama's own API on port 11434 with its native routes. In the second, it uses the OpenAI-style route under /v1 through an OpenAI SDK or a tool that offers a custom endpoint. The second pattern is nearly a one-line change. The first needs a small rewrite, because the hosted API accepts the OpenAI chat format and not Ollama's native one.

If you are not sure which one you have, search your code or config for the string 11434 and for paths such as /api/chat versus /v1/chat/completions. If you want background on what Ollama's interface offers, the article What is the Ollama API covers the basics.

The switch in three values

For a client that already uses the OpenAI format, these are the only changes.

ValueLocal OllamaHosted API
Base URLhttp://localhost:11434/v1https://api.ollamansfw.top/v1
API keyAny placeholderYour real key
ModelThe tag you pulleduncensored

You get a key on the API key page. Sign up with Google, or with email and password, then claim the trial credit of $0.50 with one click. It is one per person, valid for 7 days. That is enough to run every test in this article.

Here is the switch in Python, written so that you can flip between local and hosted with an environment variable. That way a failed network day does not stop you.

import os
from openai import OpenAI

USE_HOSTED = os.getenv("USE_HOSTED", "1") == "1"

if USE_HOSTED:
    client = OpenAI(base_url="https://api.ollamansfw.top/v1",
                    api_key=os.environ["API_KEY"])
    MODEL = "uncensored"
else:
    client = OpenAI(base_url="http://localhost:11434/v1", api_key="local")
    MODEL = "your-local-model-tag"  # hosted ID is "uncensored"

r = client.chat.completions.create(
    model=MODEL,
    messages=[{"role": "user", "content": "Write a two-line greeting."}],
)
print(r.choices[0].message.content)

In Node, the same idea uses the official OpenAI package:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.ollamansfw.top/v1",
  apiKey: process.env.API_KEY,
});

const r = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Write a two-line greeting." }],
});
console.log(r.choices[0].message.content);

Switching tools that have a settings screen

Many front ends and agents let you pick a provider in a menu instead of in code. Look for an option named something like custom endpoint, OpenAI-compatible or generic OpenAI. Enter the base URL ending in /v1, paste the key and type uncensored as the model. Do not add a route such as /chat/completions to the URL unless the tool tells you to, because the client adds it.

If a tool supports only the Ollama provider and offers no custom OpenAI endpoint, you cannot point it at a hosted API directly. In that case look for an update, or run a small local proxy that translates, but that is more moving parts than most people want.

A layered test that finds problems fast

Run four checks in this order. Each one proves one more thing, so a failure tells you where to look.

  1. Models call. GET /v1/models with your key. If it lists uncensored, URL and key are right.
  2. Plain request. One short non-streaming chat completion. If this fails after step 1 passes, the body or model name is wrong.
  3. Streaming. Add stream: true and make sure tokens arrive progressively. Usage is reported at the end of the stream.
  4. Tools or JSON mode. Only if your app uses them. The API supports tools and tool_choice, streamed tool_calls, and response_format: {"type":"json_object"}.
curl https://api.ollamansfw.top/v1/models   -H "Authorization: Bearer YOUR_API_KEY"

curl https://api.ollamansfw.top/v1/chat/completions   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"model":"uncensored","stream":true,"messages":[{"role":"user","content":"Count to three."}]}'

Keep the X-Request-Id response header when you report a problem, and glance at X-Balance-USD to see how much credit remains.

Planning the rollout

If the app is only for you, switch in one step and move on. If other people use it, a staged rollout is safer and costs little extra effort.

  1. Shadow period. Keep local Ollama as the live backend for a day or two. Send a copy of a few real prompts to the hosted endpoint from a script and read the answers next to each other. You are judging whether replies suit your use, not whether they match word for word.
  2. Partial traffic. Route a small share of users or one feature to the hosted base URL, using a flag in your config. Watch error rates, especially 429 responses, and watch the balance header to confirm your cost estimate.
  3. Full cut-over. Move everything once the numbers look right, but leave the flag in place. A one-line fallback to local Ollama is worth keeping for the day your network or your credit runs out.
  4. Clean-up. Remove unused model files only when you are sure you will not use them again. Disk space is cheaper than a re-download.

Prompts also deserve a look. System prompts written to coax a restrictive local model often contain long disclaimers or workarounds. With a model tuned for lawful adult use without refusals, you can usually shorten them, which reduces input tokens on every single call. Read the shortened version aloud: if it states the task and the tone plainly, it is probably enough.

Finally, decide who holds the key. A key in a server environment variable is fine. A key shipped inside a browser or mobile bundle can be copied by anyone, so call the API from your own backend and let your front end talk to that.

What you give up and what you gain

Be honest about the trade. Moving to the hosted API gives you no hardware to run, an endpoint that stays up when your computer is off, and a 100,000-token context window shared by prompt and completion. The model is tuned to answer without content refusals for lawful adult use, which matters for fiction and companion apps for adults. Prompts are not used for training.

You give up some things too. It is text only: no image, audio or video generation, no embeddings and no fine-tuning. It is one model from an independent provider, not a router across vendors and not the official API of any of them. You cannot pull a different model tomorrow. Everything leaves your machine over the network, so if you must stay fully offline, keep Ollama. The hard content rule is also fixed: no sexual content involving minors.

Limits and cost after the switch

A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 and 60. The maximum body is 8 MB. If you exceed a limit, you get HTTP 429 with the code rate_limited or concurrency. Temporary overload also gives a 429 with Retry-After: 5. A streaming request holds its concurrency slot until the stream finishes, so an app that opens many streams needs a queue. A simple retry that sleeps for the stated interval is enough in most cases.

Billing is per token from prepaid credit: $0.15 per 1M input tokens and $0.50 per 1M output tokens. Consider a bot that handles 500 messages a day, each with 3,000 tokens of input and 250 tokens of output.

  • Daily input: 500 x 3,000 = 1,500,000 tokens, which is $0.225
  • Daily output: 500 x 250 = 125,000 tokens, which is $0.0625
  • Daily total: $0.2875. Over 30 days: $8.625.

Top-ups are any whole amount from $20 to $500, with +5% from $50, +10% from $100 and +15% from $200, paid in crypto (USDT on TRC20 or USDC on Base). Credit never expires and failed or refused requests are not charged. The pricing page has the details, and the docs show a ready first request.

Common mistakes after an ollama switch

  • Leaving the local model tag in place. The hosted model ID is uncensored.
  • Forgetting the key. Local Ollama ignores it, so the missing key only shows up when you switch.
  • Pointing a native Ollama client at the new URL. The hosted API speaks the OpenAI format only.
  • Sending the whole history every time without trimming. Input tokens add up. Summarize old turns once chats grow long.
  • Running too many workers. More than 8 parallel requests will hit concurrency errors.

Questions and answers

Do I have to change my code to switch from Ollama?

If your code uses the OpenAI format, only the base URL, key and model ID change. Code that uses Ollama's native routes needs a small rewrite.

Can I switch back to local Ollama later?

Yes. Keep both configurations behind an environment variable and flip between them.

Does the hosted API have embeddings?

No. It supports chat completions and the models list only, so keep embeddings elsewhere.

How do I pay for credit?

With crypto: USDT on TRC20 or USDC on Base, in any whole amount from $20 to $500.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.