Reach Your Home AI Server from Android with Ollama and Tailscale
Most developers assume that because their phone and server sit on the same Wi-Fi, connectivity is automatic.

Most developers assume that because their phone and server sit on the same Wi-Fi, connectivity is automatic. That is the trap. Ollama binds to 127.0.0.1 by default, meaning only programs running directly on the server itself can reach it. If you do not explicitly configure the host binding, your Android app will fail to connect, leaving you with a powerful local GPU that remains invisible to your phone.
The book opens its homelab chapter with this exact configuration hurdle: Ollama’s FAQ is clear about the default binding. You have two good ways to let the phone in. One option binds to the network interface; the other keeps Ollama on localhost and lets Tailscale Serve front it. This post covers the setup rules, how to prove connectivity with curl, and the Kotlin backend needed to stream replies into your app.
One caveat, straight from the book: the Ollama API needs no key. The documentation examples are plain curl calls with no credentials. Anyone who can reach port 11434 can use your models and your GPU, and can pull or delete models through the same API. Never forward that port on your router to the internet. Use the LAN at home and Tailscale away from it.
The trap: assuming localhost is reachable
The usual way people find out their setup is broken is that the app throws a connection refused error. The book’s answer is to make the server reachable on purpose. You have two distinct paths depending on whether you are at home or away.
Option A is to bind to the network. On Linux, where Ollama runs as a systemd service, the FAQ’s method uses an override file. You run the following commands:
sudo systemctl edit ollama.service
# add these two lines in the editor, then save:
# [Service]
# Environment="OLLAMA_HOST=0.0.0.0:11434"
sudo systemctl daemon-reload
sudo systemctl restart ollama
Now any device that can reach the server’s address can use the API. On a home network, this means every device on that network.
Option B is to keep Ollama on localhost and let Tailscale Serve front it. Tailscale Serve proxies a local port to other devices in your tailnet over HTTPS. Its documentation shows the pattern with a web server on 127.0.0.1:3000; the same works for Ollama’s port. On the Ollama server, you run:
# On the Ollama server (Tailscale installed, HTTPS enabled)
tailscale serve 11434
# Serve prints the URL, for example https://ollama-box.your-tailnet.ts.net
Ollama never listens on the LAN at all. The phone connects with a real certificate, and only devices in your tailnet can reach it. Tailscale issues those certificates for your tailnet’s ts.net name.
The trap: ignoring Android’s cleartext restrictions
Even if the server is reachable, your app may still fail to connect. Since Android 9 (API level 28), cleartext HTTP is disabled by default. A plain ` request from an app targeting a current API level fails until you opt in. You have three choices here, and the book advises picking the narrowest rule that works.
The best option is HTTPS. With Tailscale Serve in front, the URL is ` and no configuration is needed.
If you stick with LAN HTTP, allow cleartext only for known hosts. If your app talks to a fixed address, configure it like this:
<!-- res/xml/network_security_config.xml -->
<network-security-config>
<base-config cleartextTrafficPermitted="false" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="false">ollama.home.arpa</domain>
</domain-config>
</network-security-config>
<!-- AndroidManifest.xml -->
<application
android:networkSecurityConfig="@xml/network_security_config"
... >
When users type any address, a general client cannot know the server’s address at build time. In that case, ollama-android-client allows cleartext in base-config. The documentation calls this configuration insecure and says to avoid it whenever possible. If your app needs it, keep it, say so in your privacy policy, and nudge users toward HTTPS in your setup screen.
The trap: treating the stream as a single response
Ollama’s /api/chat is a streaming endpoint by default. The reply arrives as a series of JSON objects, one per line. If you treat the response as a single block, you will either hang waiting for an end-of-stream marker that never comes in the way you expect, or you will miss the final statistics.
Each line is a complete JSON object with a message containing the next piece of content and "done": false. The final object has "done": true and adds statistics such as total_duration, eval_count (tokens generated), and eval_duration (nanoseconds). Thinking-capable models also send a thinking field alongside content. If something goes wrong after the stream has started, the errors page says the server sends an object with an error field in the same stream. The HTTP status stays 200 because the response has already begun.
You must prove connectivity before writing Kotlin code. From a laptop on the same network or tailnet, list the models and send one chat:
curl http://192.168.1.50:11434/api/tags
curl http://192.168.1.50:11434/api/chat -d '{
"model": "gemma3",
"messages": [{ "role": "user", "content": "Say hi in five words." }]
}'
Pull the model first on the server (ollama pull ) if it is not in the tags list. The model names here are examples; use the ones your server has.
The trap: underestimating startup latency
A server that has to load a large model into GPU memory before the first token can take a while to say anything. OkHttp’s default read timeout is too short for that. If you do not adjust timeouts, your app will time out during the initial generation phase, even if subsequent tokens arrive quickly.
ollama-android-client builds a per-request client from a user setting (requestTimeoutSeconds in its UiPreferences) in data/api/OllamaStreamingService.kt:
val client = okHttpClient.newBuilder()
.connectTimeout(timeoutSecs, TimeUnit.SECONDS)
.readTimeout(timeoutSecs, TimeUnit.SECONDS)
.writeTimeout(timeoutSecs, TimeUnit.SECONDS)
.build()
newBuilder() shares the connection pool and dispatcher with the original client, so this is cheap. Expose the timeout in settings; users with slow first loads will thank you. Note that Ollama keeps a model in memory for a while after a request (the API reference gives a default keep_alive of five minutes) so the next message starts fast. The keep_alive field on /api/chat changes that per request, and the OLLAMA_KEEP_ALIVE environment variable changes the server default.
Checklist
- Override Ollama’s systemd service to bind
0.0.0.0:11434or use Tailscale Serve for HTTPS. - Verify connectivity with `curl before touching Android code.
- Configure
network_security_config.xmlto permit cleartext only for known LAN hosts, or prefer HTTPS via Tailscale. - Parse the streaming
/api/chatresponse line by line, checking for"done": trueand"error"fields. - Set OkHttp timeouts (
connectTimeout,readTimeout,writeTimeout) to accommodate slow GPU model loading. - Normalize user input URLs to strip
/api/paths and ensure a trailing slash before passing them to Retrofit. - Check availability via
/api/tagson the first run, suggestingollama pullif the model is missing.