Sharing an OpenCode setup in your repository without sharing the key

Coding with AIOpenCode·· 7 views· 3 min read

The project's opencode.jsonc can go into the repository. Whoever clones it gets the Interweb provider, the models and the starting model ready. The key stays out: each person uses their own, in a variable with the same name.

What goes into the file

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"api": {
"npm": "@ai-sdk/openai-compatible",
"name": "Interweb",
"options": {
"baseURL": "https://api.interweb.co.mz/v1",
// The key comes from the INTERWEB_API_KEY variable: each person uses their own.
"apiKey": "{env:INTERWEB_API_KEY}"
},
"models": {
"moonshotai/kimi-k2.7-code": { "name": "Kimi K2.7 Code", "limit": { "context": 262144, "output": 16000 } },
"deepseek-ai/deepseek-v4-pro": { "name": "DeepSeek V4 Pro", "limit": { "context": 1048576, "output": 16000 } },
"zai-org/glm-5.2": { "name": "GLM 5.2", "limit": { "context": 1048576, "output": 16000 } },
"deepseek-ai/deepseek-v4-flash": { "name": "DeepSeek V4 Flash", "limit": { "context": 1048576, "output": 16000 } }
}
}
},
"model": "api/moonshotai/kimi-k2.7-code"
}

Name it opencode.jsonc and put it at the root of the project. The comment is only accepted in a .jsonc file. OpenCode finds the file when someone opens it in that folder or in a subfolder.

What each person does

1 Creates their own key in the API Center, with ai:read and ai:write.
2 Saves it in the INTERWEB_API_KEY variable on their computer, with exactly this name, which is the one in the file: setx on Windows, export on Linux and macOS.
3 Opens a new terminal, starts OpenCode in the project folder and types /models.

Anyone without the variable gets a 401, because OpenCode sends an empty key. Nobody else is affected.

One key per person

Each key has a name and can have a spending limit and a list of IPs: see creating an API key. With one key per person, if someone leaves the team or a key is exposed, you revoke only that one and everyone else keeps working.

When the project file and the global file disagree

OpenCode joins the two. When the same setting is in both, the project one wins. So, if the shared file has "model", that is everyone's starting model in that project. Each person can still change it while working with /models.

Before the first commit, check that the file has no prod_ or sandbox_ in it. A key that went to Git must be revoked, even if you delete it in the next commit, because it stays in the history. See what to do, in the right order.
Kilo Code is different: a project file does not read variables. See why the key only works in the global kilo.jsonc.

Want your team coding with our models? Visit the Coding with AI page.

See Coding with AI

SEE ALSO

OpenCode for all projects or for one: the global opencode.jsonc and the project file

Keeping the key out of opencode.jsonc, and setx on Windows

An API key or token has leaked: what to do, in the right order

Why the key only works in the global kilo.jsonc, and not in a project's file

Coding with AI in All in One AI

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.