In Can't Beat Free: Gemma 4 31B on AMD Token Lab, with a Local Chat Page and an ADK Agent, DEV Community author xbill connects a browser chat, a terminal client and a Google ADK sample to the same AMD Token Lab model. The browser implementation offers a close look at two decisions that carry over to other hosted model prototypes. Which process holds the API key, and how does the interface recognize a reply that stops halfway through?
Put the credential in the forwarding process
The sample uses a Python HTTP server bound to the loopback address. The browser sends its model request to that local server, which forwards the request to Token Lab and attaches the bearer credential. The page can initiate a completion without putting the upstream key in its JavaScript. The completion still runs on the hosted service, so the material submitted in the chat is sent upstream.
A loopback binding suits the author's single-machine demo. If the same design were adapted for a shared internal chat, the forwarding server would need to decide which callers may send upstream requests. The two checks would happen at different boundaries. The chat service would identify its own users, and the model provider would authenticate the forwarding process.
Keep track of when a reply ends
The Python client can retry certain upstream HTTP errors before it starts reading the response body. Once the browser has displayed part of a reply, the interface has already exposed an incomplete result to the reader. The current chat code watches for the stream's completion marker and for a finish reason. If the connection ends before either signal arrives, it marks the reply as having ended early and asks the user to send the message again.
That distinction suggests a small test for a chat prototype. Disconnect after several chunks and check that the visible text is marked incomplete. Then test a request that fails before any chunks arrive and verify the retry behavior separately. xbill's timing observations came from one laptop making sequential requests to a shared endpoint. Those observations describe the author's session, while the two failure tests exercise behavior the application controls.