Contents
Data
| Request | Prompt tokens | First byte to the client (s) | While the model reads | Every (s) | Answer (s) | Result |
|---|---|---|---|---|---|---|
| Before the fix | about 256k | none | nothing | none | 524 from Cloudflare at 100 s | |
| Streamed | 388,745 | at once (200 and SSE headers) | a ": prefill" comment line | 15 | 286 | first token at 286 s; correct answer |
| Not streamed | 245,206 | 31 | one space (9 in all) | 15 | 156.6 | parseable JSON; correct answer |
Source: gw repository (docs/gorevler/G3.2-uzun-istek.md, README) and the live checks through the tunnel on 26–27 November 2026
In plain words
The AI machine on my desk runs a language model, image models and a speech model. The aim is to be my own provider for them: my agents and computers call them like a hosted model API. That needs one address, a key for each client, a record of who used what, and a way in from anywhere. gw is that front door. It serves the language model on the machine and, through Cloudflare, a service that relays traffic to the machine, to my other computers. The image and speech models sit behind the same door but are not served yet. Claude agents wrote gw at my request; other Claude agents attacked it after every step.
My view: as LLM costs rise, local AI will keep developing this way, and with developments like this we will in fact become our own providers. The main goal of gw is exactly that: to be the provider of my own language model and my other models, on one NVIDIA DGX Spark.
A model that runs is not yet a provider. Clients need one endpoint, a key each, a record of use and a way in from anywhere, and when the models do not all fit in memory, something has to decide which one runs.
Here they do not fit. The machine has 121.7 GiB of unified memory. Inkling 2 Mini on vLLM takes about 88 GiB and four to five minutes to start; the ComfyUI image, video and music models about 63 GB; a speech server about 2 GiB.
Every client had a port written into it, only Tailscale devices could reach the models from outside, and nobody owned the decision of what to stop. On 25 November Inkling was stopped to make room for ComfyUI, and a web app that depended on it silently lost its AI features. One agent had also stopped its own model server three times.
On 26 November I asked for one gateway that agents can manage and that I can reach from anywhere, “even from a session on another PC”, in Rust. From the first design commit to a panel with sessions, cache hits and speeds took 23 commits and about 20.5 hours; gw was live behind Cloudflare by about 19:40 on the first day.
What a provider needs, and what gw does
| A provider needs | What gw does |
|---|---|
| One endpoint | One OpenAI-compatible address for every model, plus /m/<id>/… for a model’s own API |
| A key per client | A gw key per machine or agent: 32 random characters, stored only as a digest, revocable |
| A record of use | Every request tied to an agent and a conversation, with tokens and speeds; no prompts stored |
| A way in from anywhere | A Cloudflare tunnel, with Cloudflare Access in front and gw’s own keys behind it |
| A decision on what runs | A manager that plans which model to stop and asks the owner first; switched off for now |
Who built it
I did not write a line of it. A Claude session in Claude Code, which the repository calls the architect, wrote the design and one brief per phase, checked each result, committed and deployed. Claude subagents (Opus) wrote all of the code. After each round a separate Claude subagent attacked the build; its findings became the next brief, and every fix came with its own test.
My part was the request, the decisions, and a yes or no on every step that touched the live machine or the internet. One decision matters below: write the gateway, but do not start models yet. The switch for that, lifecycle.enabled, is still off.
Build or buy
The closest existing project is llama-swap: Go, MIT licence, 6,326 stars, with model swapping, capacity routing, ComfyUI and audio endpoints and a UI. The design kept it as the reference and the fallback. Four things ruled out running it as it is:
- It runs each model server as its own child process. Here the servers are systemd units that must outlive a gateway restart.
- Its memory numbers are written by hand. Here
nvidia-smicannot even report GPU memory (it prints[N/A]); only/proc/meminfoshows it. - Its MCP endpoint only serves documentation. Agents cannot load or unload a model.
- It has no owner approval and no flow that adds a model and measures it.
So gw borrowed ideas instead: the capacity planner and roles from llama-swap, the systemd lifecycle and queue from model-swap-proxy, and wake, sleep and alive hooks from llmux.
How it fits together
gw is one Rust binary with 268 tests, all run against a fake backend and no GPU; the repository has the details. The switch above the diagram lights up one caller’s path at a time.
Cloudflare Access checks a service token first; gw then wants a valid Access JWT on every request, its own key as well on /v1, /m and /mcp, and refuses admin keys on this listener.
Agents on the machine reach :4000 directly. Without a key they get infer; with one they show up under its name.
The owner works through the CLI on admin.sock or the panel. Only the owner approves a stop, and gw starts or stops nothing while the lifecycle switch is off.
Data
| Part | Where | What it does |
|---|---|---|
| gw | one Rust binary, run as a systemd user unit | the gateway: three listeners, the data plane, MCP, the panel, the manager and the record |
| Cloudflare Access | Cloudflare edge | service token for machines, one-time PIN for the owner |
| Cloudflare Tunnel | cloudflared, a systemd user unit | carries requests for the hostname to 127.0.0.1:4001 only |
| Remote listener | 127.0.0.1:4001 | a gw key and a valid Access JWT on every request; admin keys refused |
| Local listener | 127.0.0.1:4000 | agents on the machine; a keyless client gets infer |
| Admin socket | admin.sock, mode 0600 | the owner's gw CLI |
| Data plane | /v1, /m/<id> | OpenAI-compatible API and raw passthrough; SSE unbuffered |
| MCP | /mcp | tools for agents; they cannot approve |
| Panel and API | /ui, /api | read-only for local clients; owner actions after `gw panel` or the Access login |
| Manager | inside gw | admission, single-flight starts, drain, memory guard, approvals |
| Planner | inside gw | the cheapest set of models to stop |
| SQLite record | inside gw | every request, with no bodies |
| systemd user units | D-Bus | started or stopped only when lifecycle.enabled is on; off on the live install |
| Model servers | 127.0.0.1 | vLLM with Inkling 2 Mini on :8020 (/v1), ComfyUI (/m/<id>, WebSocket included), a Whisper and Kokoro speech server (/v1/audio/*) |
Source: gw repository: docs/TASARIM.md §9 and §4, README, deploy/README.md
Three ways in. Agents on the machine use port 4000; a client without a key there may run models but not manage them. Remote traffic arrives on port 4001, where every request needs a key and admin keys are refused. The owner’s command line talks over a private Unix socket.
gw tells remote traffic apart by the port it arrived on, not by a header: the Cloudflare connector also connects from 127.0.0.1.
One API. Clients send OpenAI-style requests and name a model or a role such as chat. Streams pass through unbuffered; in a test gw added 2.1 ms to the first byte.
A manager that asks. When a model is wanted that is not running, a planner picks the cheapest set of models to stop, preferring ones that start fast and have not been used lately. Stopping a model marked evict: approve needs the owner’s yes. Agents can ask; they cannot approve.
The manager also keeps order: many requests for one stopped model start it once, running requests finish before a stop, and a model whose state gw cannot tell gets no traffic.
Off for now. While lifecycle.enabled is false, gw starts and stops nothing: it routes to what is already running and records what it would have stopped. The switch is checked twice, in the manager and in the systemd call. I have not turned it on.
For agents. An MCP server at /mcp lets agents list models, ask for one, release it and read usage; the README lists every tool.
Reaching it from anywhere
A Cloudflare tunnel carries one hostname to gw’s port 4001. The model API has two locks: Cloudflare Access at the edge, gw’s own key at the origin. The owner’s Access login opens the panel without a gw key, but not the model API.
The setup on 26 November, in order:
- A named tunnel,
gw, whose single rule sendsmodels.gurkanozkan.aito127.0.0.1:4001; everything else gets a 404. - An Access application on that hostname. The owner signs in by email with a one-time PIN; machines send a service token.
- A check before exposure: an unauthenticated request had to be redirected (302) to the Access login. Only then was the connector started, as a systemd user unit.
- gw’s side: every remote request must carry a valid Access token, which gw verifies itself, and requests to
/v1,/mand/mcpa gw key as well.
The live test that day:
| Request through the tunnel, 26 November | Result |
|---|---|
| No Access token | 302 to the login |
| Access token, no gw key | 401 |
| gw key, no Access token | 302 |
| Both | 200 |
| MCP | the 8 tools of that day |
/metrics with an infer key | 403 |
| A revoked key | 401 |
Three details needed a second look:
- The first DNS route went to another, older tunnel, because the default config file named it. An explicit
--config gw.ymlwith--overwrite-dnsfixed it. - cloudflared keeps idle connections for 90 s, and gw closed them after 15 s: an occasional 502. gw now keeps them 120 s, the tunnel 60.
- Cloudflare blocks Python’s default User-Agent,
Python-urllib/3.12, with a 403 (error 1010). gw’s examples send their own.
The 100-second limit
Cloudflare cuts a request with a 524 when the origin sends nothing for 100 seconds. On the Free, Pro and Business plans that cannot be changed.
A long prompt hits it with nothing broken: when I sent a 256k-token prompt to Inkling from my laptop, the model was still reading it at 100 seconds, and the laptop got a 524. The figure at the top of this page shows both fixes.
Streaming. gw sends the headers at once, then a comment line every 15 seconds until the first token. Streaming clients skip comment lines. The live check on 27 November: a 388,745-token prompt through the tunnel got its first token at 286 s, and the answer was correct.
Not streaming. gw waits 30 seconds for the model. If nothing comes, it sends a 200 and then one space every 15 seconds, which JSON allows before the body. The live check: a 245,206-token prompt got its headers at 31 s, then 9 spaces, then a correct answer at 156.6 s.
The price: once gw has sent 200, an error also arrives with status 200, so a client must check the body for error. Streaming is still the better choice.
What the reviewers found
Nothing went out through the tunnel until the findings of the last review before exposure were fixed. The first review counted 0 critical, 1 high and 9 medium findings. Each entry below is the attack, what it did, and the fix.
A path with .. in it. The attack was /m/x/ws/../v1/chat/completions. ComfyUI’s /ws paths are exempt, so that a browser tab watching ComfyUI cannot start a model, and gw saw /ws. The HTTP library then collapsed the .., and a chat request reached the model with no slot, counter or record. The fix checks the path the model will receive and refuses ...
A web page on the same machine. Through DNS rebinding or a cross-site request, a page open in a browser could drive port 4000. The fix: the Host must be local, a foreign Origin is refused, and JSON endpoints require a JSON content type.
A huge body. A 100 MB JSON body made gw use about three times that in memory, which the models need. Bodies are now capped, charged to a budget and not copied; the same body costs about its own size.
A nosy key. A restricted remote key could list every model and the names of other keys. Now a key sees only its own models, and a model it may not use answers 404, like one that does not exist.
Bodies promised, never sent. Sixteen connections each declared a 32 MiB body and sent nothing; 80 of 80 normal requests then got a 503. Memory is now charged as bytes arrive and a silent body times out. Afterwards 79 of 80 got 200, and the stalled connections got 408 at 30 s.
A slow drip. One key sending a byte every 25 seconds held all of a model’s slots, so a single leaked key could lock everyone out of Inkling. Now one key holds at most half of a model’s slots, and an upload must keep a minimum speed. Two colluding keys could still fill every slot, so uploads together may hold only half.
A session flood. 5,000 MCP initialize calls from one key raised gw’s memory by about 300 MB. Sessions are now capped, time out and are rate-limited; the same flood adds 5 MB.
A browser login on the model API. The owner’s browser login could start a model with a plain GET to /m/…. Browser logins now open the panel and /api only.
An expensive comparison. After gw went live, a benchmark comparison with 4,000 repeated ids used 96 s of CPU; the ids are now counted before anything is read. A remote key could also read the expected answers of custom benchmarks; they are now hidden.
What none of them found. A way to start or stop a model while the lifecycle is off. An open route on the remote port: 22 of 22 probed routes answered 401. A forged admin: all 31 forged Access tokens, unsigned and expired ones among them, were refused.
What the panel shows
The panel at /ui is built into the binary, with no build step and no CDN. The sessions view and the performance strip exist because I asked to see sessions, the cache hit rate, and prefill and decode speeds directly.

Every request is tied to an agent, by its key, a header, its MCP name or the local process behind the connection, and grouped into conversations. No prompt or answer is stored.

Per-request cache numbers needed one vLLM flag, --enable-prompt-tokens-details, turned on on 27 November. A repeated 11k prompt then showed 11,072 of 11,129 tokens cached, and its first token came after 1.5 s instead of 14.8 s.
One hour of mostly serving experiments on 27 November, as gw perf --window 1h summed it:
| Measure | Value |
|---|---|
| Requests | 127, with 1 error |
| Prompt tokens | 7.0M |
| Cache hits | 86.4%, or 88.5% where requests report it |
| Decode speed | 42.2 tok/s on average |
| Time to first token | 1.9 s at the median, 10.8 s at p95 |
| KV cache | peak 48%, 0 preemptions |

What Inkling behind it handled
A serving test on 27 and 28 November ran four coding agents against Inkling, each with about 240k tokens of context from real source repositories, growing to about 270k over six turns. They answered 40 of 40 retrieval questions and finished 4 of 4 coding tasks. Warm turns found 97.7% of their prompt in the prefix cache, with 0 preemptions.
The cold start is the weak part: prefills run one at a time, so the fourth agent waits about 10 minutes, and warm turns still take 10.5 to 14 s to the first token at the median. A client rule came out of it: keep reasoning_effort constant within a conversation, because changing it drops the cache.
If you build one
- Keep the model servers as systemd units the gateway does not own, so they outlive a gateway restart.
- Tell remote traffic apart by the port it arrives on, not by a header; the tunnel’s connector also comes from 127.0.0.1.
- Behind Cloudflare, a long prompt needs bytes before 100 seconds: stream, or send a heartbeat.
- Only append to an agent’s context; an edit in the middle means the whole prompt is read again.
- Have a separate agent attack every round, and fix what it finds before anything is exposed.
Where it stands
So far gw makes this machine a provider for one model. Inkling is served live through gw, on the machine and through the tunnel, with a key per machine.
The image and speech models sit in the same catalogue, behind the same door, but on 28 November they were not being served: ComfyUI listened on another address, and the speech unit had failed. The OpenAI-style image endpoint is not built. Neither is the easy model adding I asked for (gw add, pull, calibrate), and with the lifecycle switch off, the choice of which model to stop is still made outside gw.
The code, with the design and every brief in Turkish, is public at github.com/ozkangrk/gw under Apache-2.0: a cleaned copy in one commit, without the names of other private projects or machine-specific paths.
Sources
- gw: the design, the briefs and review findings and the tunnel setup.
- llama-swap, model-swap-proxy and llmux, read on 26 November 2026.
- The live checks and the
gw perfsummary from the session that built gw; the four-agent test from my serving notes of 27 and 28 November, which are not public.
I asked for gw and made the decisions named here. Claude, working in Claude Code, wrote the design and the task briefs, Claude subagents wrote all of the code, and separate Claude subagents did the reviews. Claude also drafted this essay from the repository’s records and took the screenshots from the live panel; a separate Claude session checked its facts against those records, and the essay was published at my request on 28 November 2026 and revised for readability, also at my request, the same day.