Skip to content
/v1 base URL

Your model, from anywhere.

Any OpenAI-compatible client takes a base_url. Point it at your tunnel and pass your zgrok AI token as the api_key, and the client talks to the model on your own machine.

~/app · An app calling your model
$ zgrok ai
✓ Online · llm--acme-shop.zgrok.io/v1
GET/v1/models2006 ms
POST/v1/chat/completions2003.2 s
POST/v1/embeddings200310 ms
POST/v1/chat/completions2008.9 s
On this page

Read this part before you paste that URL into a config file.

On the free plan the address zgrok assigns you is rewritten every session, so a 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.

bash
curl https://llm--acme-shop.zgrok.io/v1/models \
  -H "Authorization: Bearer YOUR_TOKEN"
401

The token

It is missing, or it is not the one this run printed.
404

The address

No tunnel is running under that name. On Free, check whether it changed.
503

The model server

The tunnel is up, and nothing is listening on the local port.

Python

The official openai package takes both values in its constructor. Nothing else about the script changes.

python
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.

base_url

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.
model

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.

from openai import OpenAI client = OpenAI( base_url="https://llm--acme-shop.zgrok.io/v1", # moves on Free api_key="zg_ai_xxxxxxxxxxxxxxxxxxxxxxxx", # your zgrok ai token )

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.

typescript
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 staging deployment or a branch preview can use the GPU under your desk while you are working on the feature, without a model-provider account or a per-token bill for throwaway requests.

A notebook or a script on a machine that cannot run the model.

A laptop with no GPU, a cheap VM, a CI job you are debugging. The client is two values away from the model you already have loaded.

A teammate who wants to try it.

They get a URL and a token, and set the same two values the snippets above set. Nothing to install and no weights to pull is a much shorter conversation than talking someone through a local setup.

An automation that runs somewhere else.

A scheduled job, a webhook handler, a bot. Anything that can set a base URL can reach the model.

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.

If something you are not sitting in front of is going to call this URL on a schedule, fix the address first.

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.

--subdomain

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.
ai_token

The credential is fixed by pinning it.

Put 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

Run your first tunnel.

Free to start. $9 for a URL that stays. You pay for features, never for traffic.