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
- ZDR
Use the local Confidential Proxy for sensitive prompts and source code. Go to the confidential setup.
Confidential API setup
This path uses the local Confidential Proxy to encrypt your prompts end-to-end before they leave your machine.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:deepseek-v4-flash.
Inspect the response model field. The requested alias deepseek-v4-flash currently resolves to prem-research/DeepSeek-V4-Flash-0731-abliterated. 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
deepseek-v4-flash 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
deepseek-v4-flash 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.ZDR setup
ZDR uses a separate OpenCode provider. It does not use the Confidential Proxy, client KEK, or attestation path. Confirm thatkimi-k3 appears in GET /openai/models for this key. Otherwise, use
an exact returned model ID. See Models & Pricing.
1. Set your API key
{env:PREM_API_KEY}
reference in the provider config below.
2. Configure OpenCode
Add theprem-zdr provider in opencode.json at the project root:
Change
kimi-k3 to the model your key can use in both model and models.
Keep the provider names separate when both paths are configured:
3. Verify
Run a model-list check, then a bounded request, then start OpenCode:opencode models prem-zdr should list prem-zdr/kimi-k3. The bounded request should
return PREM_ZDR_OK. Use a model ID your key can use if your key does not have kimi-k3.
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.