Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

serve: reachable from other devices on the network (issue #26)

Niko1221868dc724d6a1
diff --git a/docs/DETAILS.md b/docs/DETAILS.md
index 9c3907e22..9b94718a3 100644
--- a/docs/DETAILS.md
+++ b/docs/DETAILS.md
@@ -220,8 +220,14 @@ print(r.choices[0].message.content)
`max_tokens` would run past the context is refused too (400); agents that always ask for their full output cap
can instead get it shortened to the room left: add `"fit_max_tokens": true` to `strata-<model>.json` (or pass
`--fit-max-tokens` to `serve/server.py`). A prompt that leaves no room at all is still refused.
-- **From other devices / the internet.** The server listens on your PC only (`127.0.0.1`). To reach it from elsewhere,
- put a tunnel in front of it, for example [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/):
+- **From other devices on your network.** The server listens on your PC only (`127.0.0.1`) unless you say otherwise:
+ run setup with `START-HERE.bat --setup --host 0.0.0.0 --api-key some-long-secret` (or add `"host": "0.0.0.0"` and
+ `"api_key": "..."` to `strata-<model>.json`). The server window then prints this PC's addresses
+ (`from other devices: http://192.168.x.x:8080/`); open that on the other device, or use `.../v1` as an API base URL.
+ On Windows the firewall blocks it until you allow it: accept its prompt for Python (private networks), or run
+ `New-NetFirewallRule -DisplayName "Strata 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow -Profile Private`
+ in an admin PowerShell, and make sure the network is set to Private.
+- **From the internet.** Put a tunnel in front of it, for example [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/):
`cloudflared tunnel --url http://127.0.0.1:8080`. **Set a key first**, or anyone with the link can use your PC:
add `"api_key": "some-long-secret"` to `strata-<model>.json` (or set the `STRATA_API_KEY` environment variable);
clients then send it as their API key.
diff --git a/serve/server.py b/serve/server.py
index 31800602a..73e7c6f27 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -922,6 +922,25 @@ class Server(ThreadingHTTPServer):
allow_reuse_address = os.name != "nt"
+def lan_addresses() -> list[str]:
+ """This PC's IPv4 addresses on its networks (what another device types in), without loopback/link-local."""
+ import socket
+ first, ips = None, set()
+ try: # the address of the default route; sends nothing (UDP)
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
+ s.connect(("10.255.255.255", 1))
+ first = s.getsockname()[0]
+ except OSError:
+ pass
+ try:
+ for info in socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET):
+ ips.add(info[4][0])
+ except OSError:
+ pass
+ ok = lambda ip: ip and not ip.startswith(("127.", "169.254.", "0."))
+ return ([first] if ok(first) else []) + sorted(ip for ip in ips if ok(ip) and ip != first)
+
+
def serve(svc: Service, host="127.0.0.1", port=8095) -> ThreadingHTTPServer:
svc.start_telemetry()
httpd = Server((host, port), make_handler(svc))
@@ -987,7 +1006,9 @@ def main() -> int:
ap.add_argument("--engine", choices=["mock", "strata"], default="mock")
ap.add_argument("--config", help="strata engine config (JSON: exe, args, cwd, tokenizer, model_name), "
"written by setup.py")
- ap.add_argument("--host", default="127.0.0.1")
+ ap.add_argument("--host", default=None,
+ help="the address to listen on: 127.0.0.1 = this PC only (the default), 0.0.0.0 = also other devices "
+ "on your network (set an API key); also \"host\" in the config")
ap.add_argument("--script", default="Thinking about it.</think>\n\nHello from the mock engine.")
ap.add_argument("--port", type=int, default=8095)
ap.add_argument("--tokenizer", default=str(ROOT / "pack/full/tokenizer"),
@@ -1000,6 +1021,7 @@ def main() -> int:
help="require this key on /v1/* (Authorization: Bearer ... or x-api-key); also $STRATA_API_KEY")
a = ap.parse_args()
cfg = json.loads(Path(a.config).read_text(encoding="utf-8-sig")) if a.config else {} # Notepad adds a BOM
+ a.host = a.host or cfg.get("host") or "127.0.0.1" # issue #26: the run scripts pass no --host, the config can
try: # before the minutes of loading: is the port free?
Server((a.host, a.port), BaseHTTPRequestHandler).server_close()
except OSError:
@@ -1045,10 +1067,26 @@ def main() -> int:
fit_max_tokens=a.fit_max_tokens or cfg.get("fit_max_tokens") is True)
svc.api_key = a.api_key or cfg.get("api_key", "")
httpd = serve(svc, host=a.host, port=a.port)
- print(f"ready: http://{a.host}:{a.port}/v1 (OpenAI: /v1/chat/completions, Anthropic: /v1/messages, "
+ here = "127.0.0.1" if a.host in ("0.0.0.0", "", "::") else a.host
+ print(f"ready: http://{here}:{a.port}/v1 (OpenAI: /v1/chat/completions, Anthropic: /v1/messages, "
f"context {engine.max_context} tokens{', images on' if vision else ''}"
f"{', API key required' if svc.api_key else ''})", flush=True)
- print(f" open http://{a.host}:{a.port}/ in a browser to chat; close this window to stop the model", flush=True)
+ print(f" open http://{here}:{a.port}/ in a browser to chat; close this window to stop the model", flush=True)
+ if a.host not in ("127.0.0.1", "localhost", "::1"):
+ # issue #26: reachable from other devices - say at which address, and what can still block it
+ ips = lan_addresses()
+ for ip in ips:
+ print(f" from other devices: http://{ip}:{a.port}/ (API: http://{ip}:{a.port}/v1)", flush=True)
+ if not ips:
+ print(" from other devices: http://<this PC's IP address>:" + str(a.port) + "/", flush=True)
+ if not svc.api_key:
+ print(" WARNING: no API key - anyone on your network can use this model. Add \"api_key\": \"...\" "
+ "to the config (clients send it as their API key; the web page asks for it)", flush=True)
+ if os.name == "nt":
+ print(" nothing arrives? Windows Firewall blocks it until allowed: accept its prompt for Python, or run "
+ "in an admin PowerShell:\n New-NetFirewallRule -DisplayName \"Strata " + str(a.port) + "\" "
+ "-Direction Inbound -Protocol TCP -LocalPort " + str(a.port) + " -Action Allow -Profile Private\n"
+ " (and set this network to Private in Windows' network settings)", flush=True)
if a.open:
import webbrowser
webbrowser.open(f"http://{'127.0.0.1' if a.host in ('0.0.0.0', '') else a.host}:{a.port}/")
diff --git a/setup.py b/setup.py
index 374385d41..b46653a18 100644
--- a/setup.py
+++ b/setup.py
@@ -653,6 +653,9 @@ def main() -> int:
ap.add_argument("--vision", choices=["yes", "no", "none", "gpu", "cpu"],
help="let the model read images (yes = the encoder on the GPU)")
ap.add_argument("--port", type=int, default=8080)
+ ap.add_argument("--host", help="where the server listens: 127.0.0.1 = this PC only (default), 0.0.0.0 = also other "
+ "devices on your network (issue #26; set --api-key too)")
+ ap.add_argument("--api-key", help="require this key from clients (recommended with --host 0.0.0.0)")
ap.add_argument("--models-dir", default=str(ROOT / "models"), help="where the GGUF files go (~70 GB)")
ap.add_argument("--gguf-dir", help="use GGUF files you already have (a folder with the two shards)")
ap.add_argument("--yes", action="store_true", help="accept the recommended answers")
@@ -896,6 +899,10 @@ def main() -> int:
cfg = {"exe": str(eng / EXE), "args": args, "cwd": str(ROOT), "tokenizer": str(pack / "tokenizer"),
"model_name": f"{fam['name']}-{model.lower()}", "log": str(ROOT / f"strata-{tag.lower()}.log"),
"lib_dirs": lib_dirs, "port": a.port}
+ if a.host:
+ cfg["host"] = a.host
+ if a.api_key:
+ cfg["api_key"] = a.api_key
if vision != "none":
cfg["vision"] = {"exe": str(eng / VEXE), "mmproj": str(mmproj), "model": str(shards[0]),
"gpu": vision == "gpu", "max_tokens": VISION[vision]["max_tokens"]}
@@ -910,6 +917,9 @@ def main() -> int:
say("All set.")
say(f" API (OpenAI): http://127.0.0.1:{a.port}/v1 (any API key; model name: anything)")
say(f" API (Anthropic): http://127.0.0.1:{a.port}/v1/messages")
+ if a.host and a.host not in ("127.0.0.1", "localhost"):
+ say(f" Other devices: the server window prints this PC's address (http://<IP>:{a.port}/)"
+ + ("" if a.api_key else " - no API key set: anyone on your network can use it"))
say(f" Next time: just run {'START-HERE.bat' if WIN else './setup.sh'} (or {script.name}) - it starts right away")
if vision != "none":
say(" Images: send them in the chat page, in chat.py (/image <path>) or over the API")