Use GLM, Kimi and MiniMax coding plans
OpenCode runs against a provider plan you already pay for: Z.ai’s GLM Coding Plan directly, and Kimi, MiniMax, DeepSeek, OpenRouter or a self-hosted gateway through any OpenAI-compatible endpoint. For Claude Code or Codex on their own plans, see Claude Code on your Claude plan and Codex on your ChatGPT plan.
Every recipe has three parts: store the key as a secret, name it with
apiKeyEnv, and grant it with secrets. The key never appears in the create
request, and the platform mints no Router key for the sandbox.
Z.ai GLM Coding Plan
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
await client.secrets.create("ZAI_KEY", process.env.ZAI_API_KEY!);
// The plan key drives OpenCode; Claude Code and Codex sign in with their own plans.
const box = await client.create({
backend: {
type: "opencode",
model: {
provider: "zai-coding-plan",
model: "<model-id>",
apiKeyEnv: "ZAI_KEY",
// For keys bought on z.ai; omit for open.bigmodel.cn keys.
baseUrl: "https://api.z.ai/api/coding/paas/v4",
},
},
secrets: ["ZAI_KEY"],
git: { url: "https://github.com/tangle-network/sandbox-demo" },
});
try {
const run = await box.prompt("Write a CLI that converts CSV to JSON.", { sessionId: "main" });
console.log(run.success ? run.response : run.error);
} finally {
await box.delete();
}Without baseUrl, zai-coding-plan calls
https://open.bigmodel.cn/api/coding/paas/v4. Keys from z.ai and from BigModel
belong to separate accounts, so match the endpoint to where you bought the
plan. Use the model ids from your plan’s model list.
Kimi, MiniMax and other OpenAI-compatible providers
provider: "openai-compat" takes any base URL that serves
/chat/completions. Set baseUrl to the URL up to, but not including,
/chat/completions, and model to the id that provider lists. Like the Z.ai
recipe, this runs OpenCode, not Claude Code or Codex.
await client.secrets.create("MOONSHOT_KEY", process.env.MOONSHOT_API_KEY!);
const box = await client.create({
backend: {
type: "opencode",
model: {
provider: "openai-compat",
baseUrl: "https://api.moonshot.ai/v1",
model: "<model-id>",
apiKeyEnv: "MOONSHOT_KEY",
},
},
secrets: ["MOONSHOT_KEY"],
});| Provider | baseUrl |
|---|---|
| Kimi (Moonshot) | https://api.moonshot.ai/v1 |
| MiniMax | https://api.minimax.io/v1 |
| DeepSeek | https://api.deepseek.com/v1 |
| OpenRouter | https://openrouter.ai/api/v1 |
Each provider publishes its own model list; take the model id from there.
OpenCode accepts these provider values: openai, anthropic,
openai-compat, openrouter, zai (and zai- variants such as
zai-coding-plan), codex-cli and claude-code. A baseUrl on z.ai or
bigmodel.cn selects Z.ai, and one containing openrouter selects OpenRouter.
These values configure OpenCode only; Claude Code and Codex have their own pages.
Check where the model calls went
Egress activity lists every host the sandbox reached, so you can confirm the agent called your provider:
const activity = await box.egress.activity({ limit: 100 });
for (const destination of activity.destinations) {
console.log(destination.action, destination.host, destination.count);
}
if (!activity.complete) console.log("Partial:", activity.incompleteReasons);activity.complete is false when part of the record could not be read. The
call answers 409 on a sandbox without egress control enabled. To make the
provider the only host the agent can reach, create the sandbox with a strict
egress policy. See Network access.
Troubleshooting
| Message | Fix |
|---|---|
backend.model.apiKeyEnv names ZAI_KEY, which is not a selected secret or proxy alias | Add the secret to secrets. |
Unsupported OpenCode provider "..." | Use one of the provider values above. |
| A 401 from the provider | Check that the key and baseUrl belong to the same account (z.ai or BigModel). |
For Claude Code and Codex sign-in errors, see their own pages.
Next
- Run a coding agent
- Secrets: how stored keys are kept and delivered.
- Network access