OpenCode does not use the TypeScript SDK directly. It uses the OpenAI-compatible routes from the Confidential Proxy. The proxy is part of
@premai/api-sdk.- Confidential API
- Router (Beta)
Use the local Confidential Proxy for sensitive prompts and source code. Go to the confidential setup.
Confidential API
How the connection works
OpenCode and the Confidential Proxy stay on your machine. The Prem API Gateway sees only the sealed message. The Prem API Enclave opens it inside a Trusted Execution Environment (TEE).Before you start
Get these four things ready:- OpenCode, installed. See the OpenCode install guide.
- A Prem API key. This proves who you are. See API Keys.
- A client Key Encryption Key (KEK). This is a master key that protects your other keys.
- A model that your Prem account can use. See Models & Pricing.
The API key and the KEK are two different secrets. The API key handles sign-in, limits, and billing. The KEK protects your encryption keys. Keep both safe.
1. Set your secrets
Open a terminal. Set these values in the terminal that runs the proxy:PROXY_URL and ENCLAVE_URL show the current default endpoints. Check the Prem dashboard if the endpoints change.2. Start the Confidential Proxy
Start the proxy in OpenAI mode. Keep this terminal open while you work:http://127.0.0.1:8787/v1. OpenCode sends its requests there.
3. Do a proxy test
Send one request before you start OpenCode:glm-5.2.
Inspect the response model field. The requested alias glm-5.2 currently resolves to zai-org/GLM-5.2. The response does not include an assurance-profile field. See Platform Status.
Do not continue if this request does not complete. See Errors and Rate limits.
4. Configure OpenCode
Createopencode.json in the project root:
This follows the OpenCode custom provider docs. Change
glm-5.2 to the model your account uses. Change it in both model and models.
5. Start OpenCode
Start OpenCode from the folder that hasopencode.json:
What this setup protects
Good to know
Tool calls run on your machine. The model can ask OpenCode to run a tool. The model traffic uses the sealed path. But OpenCode runs the tool on your machine, outside the enclave. So keep theedit and bash permissions set to ask. Do not treat a private model as a private tool.
One stream at a time. The encrypted endpoint allows one active stream for each API key. A second stream on the same key can return 429. Start with one OpenCode session and no parallel subagents. Need parallel workers? Run them one after another, or give each worker its own API key. See Agents & Automation.
Troubleshooting
OpenCode cannot connect
OpenCode cannot connect
Check that the proxy runs at
127.0.0.1:8787. Check that baseURL ends with /v1.The proxy returns 401
The proxy returns 401
Check that
PREM_API_KEY is correct. Check that the API key is active.The API says model not found
The API says model not found
Change
glm-5.2 to a model your account can use. Change it in model and in models.The API returns 429
The API returns 429
Wait for the active stream to finish. Reduce parallel work. Follow the
Retry-After header if the response has one.OpenCode shows a different provider
OpenCode shows a different provider
Check that
enabled_providers lists only prem-confidential. Restart OpenCode after you change opencode.json.Frequently asked questions
Does OpenCode use the Prem TypeScript SDK?
No. The local proxy gives OpenCode an OpenAI-compatible interface. OpenCode does not import the SDK.Is the API key the same as the KEK?
No. The API key handles access, limits, and billing. The KEK protects your encryption keys.Does this protect my whole OpenCode session?
No. It protects the model path. OpenCode and its local tools stay on your machine.Can OpenCode use tool calls?
Yes, when the selected model supports tool calls. The model traffic uses the encrypted path. OpenCode runs each tool outside the enclave.Router
Beta Router uses a separate OpenCode provider. It does not use the Confidential Proxy, client KEK, or attestation path.kimi-k3 appears in GET /v1/models for this key. Otherwise, use
an exact returned model ID. See Router models.
Add the prem provider from the Router OpenCode configuration. Use https://router.prem.io/v1 as the base URL and start with prem/kimi-k3 as the model selector.
Keep the provider names separate when both paths are configured:
Related
Confidential Proxy
Learn the proxy modes, routes, keys, and daemon controls.
Agents & Automation
Review concurrency, retries, reasoning, and error controls.
OpenAI-compatible clients
Understand the compatibility layer that OpenCode uses.
Security Model
Learn what the enclave protects and what stays outside the TEE.
Production Checklist
Complete the key, reliability, capacity, and attestation checks.
Platform Status
Review current behavior, assurance gaps, and roadmap items.

