How to Use Ollama with OpenClaw, Local or Hosted
Here is how to use Ollama with OpenClaw, and how to swap in a hosted OpenAI-compatible endpoint when a local model is too slow or too restrictive. The agent only needs a base URL, a key and a model name.
Updated

Key points
- An agent tool talks to any backend that speaks the OpenAI chat format, local or hosted.
- For the hosted endpoint use the base URL https://api.ollamansfw.cc/v1 and the model ID uncensored.
- Agents make many calls, so watch concurrency: a full key allows 8 at once, a trial key 2.
- Check OpenClaw's own docs for the exact field names in your version.
What you are connecting
OpenClaw is an open-source agent project: a program that takes a goal, asks a language model what to do next, runs tools, and repeats. The model is a separate piece. OpenClaw does not contain one, so it needs a backend to think with. Ollama is a common local backend, and a hosted OpenAI-compatible API is a common remote one.
Configuration screens and file formats in young projects change quickly, so this article does not copy OpenClaw's config schema from memory. Instead it gives you the three values every backend needs and the order to test them in. Then you map those values onto whatever your OpenClaw version calls them. If its documentation names a provider type for Ollama and another for a custom OpenAI-compatible endpoint, you will use both below.
Step 1: get OpenClaw running with local Ollama
Start with the local path, because it proves the agent itself works before you add a network and a key to the mix.
- Install Ollama and pull one model with
ollama pulland the model name of your choice. Pick a model that supports tool calling if you want the agent to run tools, since agents depend on it. - Check the server answers. By default it listens on
http://localhost:11434. - In OpenClaw, choose the Ollama provider if it offers one, and set the host to that address. If it only offers a generic OpenAI-compatible provider, use
http://localhost:11434/v1as the base URL and any placeholder text as the key. - Set the model name to the exact tag you pulled.
- Run a trivial task, such as asking the agent to report the current directory, and watch the log for a model response.
Keep the first task small and the model output visible. If the agent cannot complete a one-step task with a local model, a longer task will not go better, and you will know the fault lies in the connection or the model choice rather than in your prompt.
If OpenClaw runs inside a container or virtual machine, localhost points at that environment, not at the machine that hosts Ollama. Use the host's address and confirm Ollama accepts connections on it.
Why local agents struggle
Agents send long prompts: instructions, tool descriptions, the history of steps so far. A small local model with a short context may lose track halfway through a task, and a model without good tool-call formatting produces malformed calls that the agent cannot parse. Many people hit these two limits first, and that is usually the reason to try a hosted endpoint.
Step 2: point OpenClaw at a hosted endpoint
The hosted API at this site is OpenAI-compatible. It accepts POST /v1/chat/completions and GET /v1/models with a bearer key. In OpenClaw, use a custom or generic OpenAI-compatible provider and fill in these values.
| Setting | Value |
|---|---|
| Base URL | https://api.ollamansfw.cc/v1 |
| API key | Your key from the account page |
| Model | uncensored |
| Streaming | On, if the agent supports it |
Create the key on the API key page. Sign-up is with Google, or with email and password. New users can claim $0.50 of trial credit with one click, one per person, valid for 7 days. Store the key in an environment variable instead of pasting it into a config file you might commit to version control.
Before you start the agent, verify the values with a plain request. If this works, any failure after that is about OpenClaw's settings, not the endpoint.
export OPENAI_API_KEY="YOUR_API_KEY"
curl https://api.ollamansfw.cc/v1/chat/completions -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" -d '{"model":"uncensored","messages":[{"role":"user","content":"Reply with OK"}],"max_tokens":5}'
If OpenClaw only accepts configuration through environment variables, the OpenAI SDK convention is OPENAI_API_KEY for the key and OPENAI_BASE_URL for the URL. Whether OpenClaw reads those depends on how it builds its client, so confirm in its docs.
Tool calling and JSON in an agent loop
Agents live and die by structured output. The hosted API supports tool calling through tools and tool_choice, streamed tool_calls, and tool results returned as messages with role: "tool". It also supports JSON mode with response_format: {"type":"json_object"}. If OpenClaw gives you a choice between native tool calls and a text format parsed from the reply, try native tool calls first, since the API implements them.
A minimal tool call looks like this when you test it outside the agent:
from openai import OpenAI
client = OpenAI(base_url="https://api.ollamansfw.cc/v1", api_key="YOUR_API_KEY")
tools = [{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a text file from the workspace",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"],
},
},
}]
r = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Open notes.txt and summarize it."}],
tools=tools,
tool_choice="auto",
)
print(r.choices[0].message.tool_calls)
If the printed value is a call to read_file with a path argument, the model and the API are doing their part. After your code runs the tool, append the result as a role: "tool" message that carries the matching call ID, and send the conversation again.
Rate limits, cost and agent loops
An agent can fire a lot of requests in a short time, especially if it runs several sub-tasks in parallel. The limits are plain: a full key allows 8 concurrent requests and 300 requests per minute, and a trial key allows 2 and 60. Past a limit the API returns HTTP 429, with the code rate_limited for requests per minute or concurrency for too many at once. Brief overload also returns 429 with a Retry-After: 5 header. Set OpenClaw's parallelism to 2 while on a trial key, and make sure its retry logic waits instead of hammering the endpoint. A streamed request keeps its slot until the stream ends.
Cost grows with every step because each call resends the history. Take an agent run of 20 steps. If each step sends 6,000 tokens of input and receives 400 tokens of output, the totals are 120,000 input tokens and 8,000 output tokens.
- Input: 120,000 x $0.15 / 1,000,000 = $0.018
- Output: 8,000 x $0.50 / 1,000,000 = $0.004
- Whole run: $0.022
So a thousand such runs cost $22. Run the numbers for your own steps and tokens before you commit a large job, because long histories dominate the bill. Prices are $0.15 per 1M input tokens and $0.50 per 1M output tokens, billed from prepaid credit with no subscription, and failed or refused requests are not charged. Top-ups go from $20 to $500 in any whole amount, with +5% from $50, +10% from $100 and +15% from $200, paid in crypto (USDT on TRC20 or USDC on Base). Details are on the pricing page.
Troubleshooting checklist
- Authorization failed. The key is missing, has whitespace, or the old placeholder is still set in the environment.
- 404 or route not found. The base URL needs to end in
/v1. Do not add/chat/completionsyourself unless OpenClaw asks for a full URL. - Model not found. Replace the local tag with
uncensored. - The agent loops or repeats itself. Lower the temperature, add a maximum step count, and add a clear stop condition in the task prompt.
- Context errors on very long runs. The window is 100,000 tokens for prompt plus completion. Have the agent summarize older steps rather than carrying them forever.
The full request reference is in the docs. If you are weighing the hosted endpoint against a local runtime in general, the article on Ollama API versus an NSFW-tuned alternative goes through the differences.
One last habit pays off in agent work. Log the X-Request-Id header with each step, so that when a run goes wrong at step 14 you can match your log with a specific request instead of guessing.
On content: the model is tuned to answer without content refusals for lawful adult use, which also reduces the stalls an agent hits when a restrictive model declines a step. One rule is fixed: no sexual content involving minors. Prompts are not used for training.
More guides
Questions and answers
Can OpenClaw use a hosted API instead of Ollama?
If it has a custom OpenAI-compatible provider option, yes. Enter the base URL, your key and the model ID uncensored, and check OpenClaw's docs for exact field names.
Does the API support tool calling for agents?
Yes. It supports tools, tool_choice, streamed tool_calls and tool results sent as role tool messages.
How do I avoid 429 errors?
Limit parallel agent calls to 8 on a full key or 2 on a trial key, and wait for the Retry-After period before retrying.
How do I pay?
Top up with crypto: USDT on TRC20 or USDC on Base, 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.