An OpenAI-compatible endpoint backed by GLM-5.2, accessible from opencode over a private Tailscale tunnel. Supports streaming, multi-turn history, system prompts, vision, and full tool calling — with automatic rate limit handling so you never see a hard 429.
POST ${BASE_URL}/api/chat${BASE_URL} with the URL of this page (the preview link).# Python — call the agent bridge from your local agent
import requests
BASE_URL = "https://preview-<bot-id>.space-z.ai" # replace with your preview URL
def ask_glm(message, system=None, history=None, thinking=False, image_urls=None):
resp = requests.post(
f"{BASE_URL}/api/chat",
json={
"message": message,
"system": system,
"history": history or [],
"thinking": thinking,
"imageUrls": image_urls or [],
},
timeout=60,
)
resp.raise_for_status()
return resp.json()["response"]
# Example: simple chat
reply = ask_glm("What is the capital of the Philippines?")
print(reply)
# Example: multi-turn with history + vision
reply = ask_glm(
"What's in this image?",
system="You are a vision assistant.",
history=[
{"role": "user", "content": "Hi"},
{"role": "assistant", "content": "Hello! How can I help?"},
],
image_urls=["https://example.com/photo.jpg"],
)
print(reply)Three steps from local code to GLM reply.
Add this bridge as a provider in your opencode config and pick GLM from the model selector.
/v1/chat/completionsglm-bridge-secret-07271991glm-4-plus, glm-4-air, glm-4v-plus...~/.config/opencode/opencode.jsonc or ~/.opencode/opencode.json) and add this provider.// /root/.opencode/opencode.json (already configured on your opencode machine)
// Uses @ai-sdk/openai-compatible with options.baseURL
// Supports tool calling — opencode can give me tasks and I can use its tools
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"glm-bridge": {
"npm": "@ai-sdk/openai-compatible",
"name": "Super Z (GLM Bridge)",
"options": {
"baseURL": "http://localhost:8443/v1",
"apiKey": "glm-bridge-secret-07271991"
},
"models": {
"glm-5.2": { "name": "GLM-5.2 (Super Z — latest, with tools)" },
"glm-5.1": { "name": "GLM-5.1 (Super Z — with tools)" },
"glm-5": { "name": "GLM-5 (Super Z — with tools)" },
"glm-4-plus": { "name": "GLM-4-Plus (flagship)" },
"glm-4-air": { "name": "GLM-4-Air (fast)" },
"glm-4-flash": { "name": "GLM-4-Flash (free)" },
"glm-4v-plus": { "name": "GLM-4V-Plus (vision)" }
}
}
}
}glm-bridge provider is in your opencode config with glm-5.2, glm-5.1, glm-5, and 8 other GLM models.localhost:8443 on opencode.opencode → type /model → pick glm-bridge/glm-5.2.The bridge auto-throttles requests, retries 429s with backoff, and pauses during cooldowns — so opencode rarely sees a hard 429.
429 status with a Retry-After header so it can back off gracefully.Everything auto-starts when the sandbox boots. The bootstrap script is hooked into the dev server startup, so opening a new chat session brings the whole tunnel back up automatically.
scripts/bootstrap.sh.zscripts/dev.shAccess this sandbox directly from your tailnet. Authenticated, encrypted, no public exposure.