OLLAMA_ORIGINS resolved a 403 when Cloud Functions called Ollama through ngrok
Key points
- Cloud Functions calls to Ollama through ngrok returned a 403; configuring
OLLAMA_ORIGINSresolved the recorded origin rejection. (Source: our own record, 2026-07-02) - The setup also required an ngrok browser-warning header, an agent upgrade, and configuration updates when the tunnel URL changed. (Source: our own record, 2026-07-02)
- A later inspection found Ollama running, no models loaded, and ngrok stopped; it did not establish the current production request path. (Source: our own measurement, 2026-10-21)
- The installed
gemma4:e4bmodel measured 9.6 GB. The approximately 14-second request time came from the earlier record and was not measured again. (Source: our own measurement, 2026-10-21; our own record, 2026-07-02)
A local fallback reached a 403 through ngrok
The setup began with an application losing access to both of its existing AI providers. OpenAI calls stopped because the quota was exhausted, and the Gemini key had been invalidated. The recorded response was to run Gemma 4 E4B through Ollama on a MacBook Pro and make it reachable from Cloud Functions through an ngrok tunnel.
The application’s call order was Ollama, then Gemini, then OpenAI. Ollama was conditional: when OLLAMA_URL was absent, the application skipped it. That configuration detail matters when describing the arrangement. The presence of a local model alone did not establish that an application request would use it; the application also needed its Ollama URL configured.
The Mac was an M1 Max machine with 64 GB of memory. Those are the specifications of the machine in this record, rather than a tested minimum requirement for this arrangement.
The failure at the center of the case was a 403 when calling Ollama through ngrok. The recorded cause was Ollama’s default rejection of origins other than local ones. Configuring OLLAMA_ORIGINS resolved that rejection.
The record therefore identifies a specific failure and a specific configuration change. It does not establish that every unsuccessful request through this setup had the same cause. Other problems appeared along the route, and they required separate changes.
Source: our own record, 2026-07-02.
The tunnel URL was only part of the configuration
Treating the public tunnel URL as the complete connection setup would have left several recorded requirements unaddressed. The URL supplied a destination for Cloud Functions, but Ollama’s origin configuration still mattered.
OLLAMA_ORIGINS is the configuration variable used to specify which origins Ollama accepts (Source: Ollama FAQ).
The setting also had to reach the Ollama process launched when the Mac started. The record says it was applied through launchctl setenv for that purpose. This makes the scope of the fix more precise: the task was to configure the Ollama process that would actually run, including the startup instance.
ngrok introduced a different requirement. Its free version inserted a browser-warning page, so the requests needed this header, preserved here exactly as recorded:
ngrok-skip-browser-warning: true
That header and OLLAMA_ORIGINS addressed different recorded obstacles. The header handled the ngrok warning page; the origin setting resolved the Ollama rejection. Neither should be presented as an interchangeable answer to the other problem.
An outdated ngrok agent was another obstacle: connections were refused until the agent was upgraded. The recorded command was:
brew upgrade ngrok
These details explain why “the tunnel exists” was not a sufficient description of a working setup. The record includes an origin setting, a request header, and an agent update. Each belongs in the account because each addressed something actually encountered.
Source: our own record, 2026-07-02.
The origin fix did not remove the operating requirements
Resolving the 403 left ongoing configuration work. In the recorded free ngrok setup, the URL changed whenever ngrok restarted. Each change required updating OLLAMA_URL in Functions and redeploying.
That requirement connects the tunnel’s state to the application’s configuration. The application had to use the changed address after a restart; an earlier successful deployment did not remove the need for the next update. The record describes this as a repeated manual task.
The Mac also had to keep the Ollama server running. The Functions-side error recorded when ollama serve was down was:
ECONNREFUSED
This is a useful distinction within this case. The 403 was associated with origin rejection. ECONNREFUSED was associated with the local Ollama server being down. A stopped server called for checking server availability, while the recorded 403 called for checking the origin configuration.
The origin change also has an exposure limit that should accompany any account of the fix. Combining OLLAMA_HOST=0.0.0.0 and OLLAMA_ORIGINS="*" with a public ngrok URL allows anyone who knows that URL to call the model. The record contains no ngrok authentication configuration.
That combination is therefore not a recommended recipe here. The alternatives identified in the record are to restrict the allowed origins, add authentication to the tunnel, or change the tunnel approach, for example to Cloudflare Tunnel. These are options for addressing exposure, not changes demonstrated as completed in this case.
The recorded result is narrower: configuring origins resolved the rejection. It does not establish an authenticated deployment.
Source: our own record, 2026-07-02.
The later inspection confirmed local state, not continued production use
The earlier model choice was gemma4:e4b. The record describes its Japanese output as natural and its JSON output as stable, with approximately 14 seconds per request. It describes gemma4:e2b as faster but somewhat weaker in multilingual quality.
Those observations belong to the July record. They are not results from the later inspection, and they do not support a performance claim for other hardware or models.
On October 21, the local checks used these recorded commands:
ollama --version
ollama list
ollama ps
The server version was 0.40.3, while the client produced a warning identifying version 0.20.0. The installed gemma4:e4b model measured 9.6 GB. That measured size superseded an earlier note describing an approximately 5 GB, four-bit model: the older description did not match the installed E4B model inspected that day.
The process check found no loaded models. The ollama serve process launched by the Ollama application was running, but ngrok was not.
Inference timing was not repeated because the Mac was under swap pressure. Consequently, the approximately 14-second figure remains an earlier observation. Reporting it alongside the later version and model size without distinguishing the dates would incorrectly suggest a fresh timing measurement.
The inspection also did not establish whether production was still routing requests through Ollama. Production configuration was not inspected. With ngrok stopped, the local observations could not demonstrate an active tunnel path from Cloud Functions.
What the evidence supports is that Ollama was used in the earlier arrangement and remained installed with its server running at the later inspection. It does not support a claim of uninterrupted production use.
Sources: our own record, 2026-07-02; our own measurement, 2026-10-21.
Watch: what quantization changes about model size
The gap between the earlier "~5 GB, four-bit" note and the 9.6 GB measured at the later inspection is a quantization question: how many bits each weight uses, and what that trades off against size and quality. A separate recorded explainer covers that mechanism.
Check the failure, the running process, and the evidence date
For a developer investigating the same arrangement, the practical lesson is to keep the recorded failure conditions separate.
If a request through ngrok returns a 403, check the origin configuration reaching the running Ollama process. In this case, configuring OLLAMA_ORIGINS resolved the rejection, and the startup-launched process also received the setting through launchctl setenv.
Check the tunnel requirements independently: the recorded browser-warning header, the agent’s ability to connect, and the address configured in OLLAMA_URL. If ngrok has restarted and its address has changed, compare that address with the application configuration before treating the earlier deployment as current.
If the error is ECONNREFUSED, check whether ollama serve is running. That was the condition associated with the error in this record. Changing allowed origins does not address the recorded stopped-server condition.
Finally, attach dates and scope to verification. A local model listing confirms what is installed. A process check establishes what was running at that inspection. Neither substitutes for checking the production configuration or measuring a fresh inference request.
This case provides a documented origin fix, several separate operating requirements, and a later snapshot of the Mac. Keeping those boundaries visible makes the account useful without turning an earlier success into an unsupported claim about the present.
Source: our own record, 2026-07-02; our own measurement, 2026-10-21.
Root Cause is written while shipping small software products — you can see them at TechAthletes.