Agent

How to Test Ollama APIs from a Browser

Ollama's local API responds fine to curl but can reject a browser-based client outright. The default allowed origins, the OLLAMA_ORIGINS fix per platform, and where Agent fits when you can't restart the server.

AlleForge TeamAugust 18, 20264 min read

Run requests against a local Ollama server from a browser-based API client, inspect the response, and understand exactly where localhost and origin restrictions can get in the way.

Before you start

  • Ollama installed and a model pulled (ollama pull llama3.2, or any model you're working with)
  • The Ollama server running — either the desktop app, or ollama serve from a terminal
  • AlleForge open, ready to build a request

Start the local API

Ollama's server binds to 127.0.0.1 on port 11434 by default (override with the OLLAMA_HOST environment variable if you need a different bind address). Once it's running, http://localhost:11434 is your base URL.

Send a request

Ollama exposes a chat endpoint at /api/chat:

POST http://localhost:11434/api/chat
Content-Type: application/json
 
{
  "model": "llama3.2",
  "messages": [
    { "role": "user", "content": "why is the sky blue?" }
  ]
}

There's also /api/generate for a single prompt instead of a message list:

{
  "model": "llama3.2",
  "prompt": "Why is the sky blue?"
}

Both endpoints stream by default — Ollama sends a sequence of JSON objects as tokens generate. Set "stream": false in the body if you want one complete JSON response instead. No real authentication applies to local requests; Ollama doesn't check for an API key on this endpoint at all.

Test it from the browser

curl isn't subject to a browser's same-origin policy — it's a standalone process, so nothing checks where the request "came from." A browser-based API client is different: before letting JavaScript read a cross-origin response, the browser requires the server to explicitly permit the calling origin. The full mechanism — origins, preflight requests, why this has nothing to do with whether the server itself is reachable — is covered in why browser API clients can't reach localhost. What's specific to Ollama is only which origins it permits by default.

Per Ollama's own documentation: Ollama allows cross-origin requests from 127.0.0.1 and 0.0.0.0 by default. Additional origins are configured with the OLLAMA_ORIGINS environment variable. A browser tool served from its own domain (not 127.0.0.1 itself) isn't on that default list, which is exactly the gap that produces a blocked request even though the server is running correctly.

Where AlleForge Agent helps

Browser

AlleForge

AlleForge Agent

127.0.0.1:11434 (Ollama)

Two ways to close this gap, not one:

  • Add AlleForge's origin to OLLAMA_ORIGINS, if you can restart the Ollama server: set the environment variable for your platform (macOS: launchctl setenv OLLAMA_ORIGINS "..."; Linux: add an Environment= line to the systemd service and reload with systemctl; Windows: set it under your account's environment variables), then restart Ollama.
  • Use AlleForge Agent when you can't or don't want to touch the server's configuration. Agent sends the request as a local process running on your own machine, outside the browser's network stack entirely — Ollama's origin allow-list is never consulted, because the request never arrives as a browser-originated cross-origin call in the first place.

Neither is universally the "right" one — restart access and how often you're switching origins both factor in. Agent doesn't fix CORS; it's a different path that bypasses the layer where CORS applies.

Troubleshooting

SymptomLikely cause
Connection refusedOllama server isn't running — start it with ollama serve or the desktop app
404 or "model not found"The model value doesn't match a pulled model — run ollama list to check exact names
Request hangs, then a generic network error in the browser consoleAlmost always the origin restriction above, not a dead server — check for a CORS-specific error in dev tools
Response is a stream of JSON lines instead of one objectExpected default behavior — set "stream": false if you want a single response
Works via curl, fails only from the browser toolConfirms it's the origin allow-list, not the request itself — see the section above

What Agent does not do

Agent provides network access between your browser and your machine. It doesn't know which model you're running, doesn't manage or restart Ollama, doesn't validate or shape the request body, and doesn't do anything specific to language models — it's the same generic bridge AlleForge uses for any other localhost or private-network API.

Sources

Ollama's default bind address, default cross-origin allowed origins, OLLAMA_ORIGINS behavior, and platform-specific environment variable setup are sourced from Ollama's own current official documentation (docs.ollama.com), fetched directly for this guide. The /api/chat and /api/generate request formats are sourced from Ollama's official API reference (github.com/ollama/ollama/docs/api.md).

See this in AlleForge

See AlleForge Agent