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.Use the bundled launcher
@premai/api-sdk includes confidential-opencode. It automates the manual setup below: it starts or reuses the local proxy in Anthropic mode, lists your enabled models, lets you pick one, and launches the installed opencode command against the local endpoint.
It needs OpenCode 2, an interactive terminal, and the same endpoints and keys as the manual setup. The launcher reads the Prem API key from API_KEY, not PREM_API_KEY:
OPENCODE_CONFIG_CONTENT and starts OpenCode with --standalone. It ignores the project opencode.json and turns off model fetching, sharing, and auto-update. It picks the model itself, so it drops --model and -m from the arguments you pass. It forwards the rest to OpenCode, which needs a subcommand before any flag. Use confidential-opencode run <args> when you pass a subcommand. Stop the proxy it started with confidential-proxy stop.
The manual steps below configure the same connection by hand. Use them when you want to control the opencode.json yourself.
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. Both OpenCode 1 and OpenCode 2 work with Prem API. Pick your version below.
- 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.
Which OpenCode version are you?
- OpenCode 1
- OpenCode 2
Install OpenCode 1:This guide shows the OpenCode 1 configuration keys (
provider, options, permission) in each setup step.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.1-flash-1017.
Inspect the response model field. The requested model deepseek-v4.1-flash-1017 resolves to the same ID. 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:
- OpenCode 1
- OpenCode 2
This follows the OpenCode custom provider docs. Change
deepseek-v4.1-flash-1017 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.
Concurrent requests per key. Each API key can run a limited number of requests at the same time, set by your tier. The encrypted endpoint always streams, and each call holds a slot until its stream closes. Requests above the limit 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.1-flash-1017 to a model your account can use. Change it in model and in models.The API returns 429
The API returns 429
Wait for active streams 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
Which OpenCode versions work with Prem API?
Both OpenCode 1 and OpenCode 2. Pick your version at the top of the setup, and each configuration step shows the keys for your version.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:
- OpenCode 1
- OpenCode 2
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.