Read this part before you paste that URL into a config file.
base_url saved today no longer reaches your tunnel the next time you start it. A stable address needs a tunnel name you choose inside your project, which is a PRO feature. Your token is separate and can be pinned in ~/.zgrok/config.yaml, so the credential stays put even while the address does not.Check the two values first
Before any SDK, ask the tunnel for its list of models. One request tells you whether the address, the token and the model server are all right, and it gives you the exact name to use as model.
curl https://llm--acme-shop.zgrok.io/v1/models \
-H "Authorization: Bearer YOUR_TOKEN"The token
The address
The model server
Python
The official openai package takes both values in its constructor. Nothing else about the script changes.
from openai import OpenAI
client = OpenAI(
base_url="https://llm--acme-shop.zgrok.io/v1",
api_key="zg_ai_xxxxxxxxxxxxxxxxxxxxxxxx",
)
completion = client.chat.completions.create(
model="llama3.2",
messages=[{"role": "user", "content": "Say this is a test"}],
)
print(completion.choices[0].message.content)Both values come off the tunnel banner.
The Base URL line
base_url is the Base URL line exactly as printed, /v1 included, which is why the CLI appends that suffix for you rather than leaving you to remember it.The model you have loaded
model is not one of those: it is whatever your own server calls the model you have loaded, so substitute the name you would have used against localhost.The api_key field deserves a second look, because the name is misleading here. It is not an OpenAI key, and no part of this request goes to OpenAI. Both SDKs treat whatever you put there as a bearer credential and send it as Authorization: Bearer <value>, which is exactly the header the tunnel checks. zgrok validates it at its own edge and then removes it from the request before forwarding, so the model on your machine is never handed your zgrok token and cannot write it to a log. Details of that check and that strip are on the pillar page.
Stripping the header is also what keeps your token from colliding with a key your model server expects for its own reasons. Note that the strip is unconditional: the Authorization header is removed whatever it holds, so it is not the channel for a second credential of your own. A server behind the tunnel that wants one has to read it from a header the tunnel does not touch.
TypeScript
The same two values, with one spelling difference that costs people a few minutes: the Node package takes baseURL and apiKey in camelCase, where the Python package takes base_url and api_key.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://llm--acme-shop.zgrok.io/v1",
apiKey: "zg_ai_xxxxxxxxxxxxxxxxxxxxxxxx",
});
const completion = await client.chat.completions.create({
model: "llama3.2",
messages: [{ role: "user", content: "Say this is a test" }],
});
console.log(completion.choices[0].message.content);The response is the ordinary completion object either SDK builds for any OpenAI-compatible endpoint, so choices[0].message.content holds the text, the same access path the SDKs use in their own published examples. The tunnel rewrites heads and copies bodies through unchanged, so what your application parses is what your own server produced.
Neither snippet hardcodes a credential in real use. Both values are ordinary configuration, and the point of the section below is that only one of them is safe to treat as permanent.
What this is good for
The shape of the thing is narrow and worth stating plainly: one machine you own, reachable by one URL, speaking an API other software already knows how to call.
An application you are building, pointed at your own hardware.
A notebook or a script on a machine that cannot run the model.
A teammate who wants to try it.
An automation that runs somewhere else.
What it does not become is a service. Requests queue behind whatever your model server does with concurrency, and the round trip includes your own upload path. Why a slow completion nonetheless survives the trip is covered on the pillar page.
What it is not good for
A long-lived production dependency on the free plan. That is not a hedge, it is the limitation at the top of this page restated as advice: on the free plan the address is a per-run value, and something else's uptime must not be resting on a value that is rewritten the next time you start the tunnel. The failure is quiet and badly timed. The config file still reads fine, the client still resolves a name, and what comes back is a 404 from an address that is no longer yours, in an application nobody changed.
There is a second, simpler dependency in the same place. The endpoint exists only while the tunnel is running and the machine is awake. A laptop that sleeps takes the model offline, and a reboot ends the run. That is fine for a work session and wrong for anything that has to answer at three in the morning.
Making it stable
A config file holds two values and they move for different reasons, so they have two different fixes. Doing one and assuming it covered the other is the mistake worth naming.
The address is fixed by naming it.
--subdomain (short form -d) is accepted by zgrok ai, not only by zgrok http, and a name you choose that way is a PRO feature. A name you introduce, rather than one the server had already handed you, is also durable in a way an assigned name is not: it stays yours afterwards, including if the plan later lapses back to free. The rewriting described at the top of this page applies to addresses the server handed you, never to one you asked for.The credential is fixed by pinning it.
ai_token in ~/.zgrok/config.yaml and every run of zgrok ai uses that token instead of generating one. The banner stops printing the note about saving a token you will not be shown again, because there is nothing new to save. This is not a paid feature and is worth doing on any plan: a client that stores a credential should not have it change underneath it.The two are independent. Pinning the token does nothing for the address, and a named tunnel does nothing for the token. Do both and the two values in your client's configuration are values you chose, which is the condition for leaving them there. The plan difference itself is on the pricing page.
Next
curl against both of its HTTP surfaces.PricingThe plan comparison, including the named tunnel the section above depends on.The local AI guideThe flag table and the security notes in full.Download the CLIIf you do not have it yet.