Use OpenCode with Aperture
Last validated:
Configure OpenCode to send requests through Aperture by Tailscale so your organization gets centralized API key management, usage tracking, and session logging.
Prerequisites
Before you begin, you need:
- An Aperture instance with at least one configured AI provider (such as Anthropic or OpenAI), accessible from your device. Refer to get started with Aperture if you have not set this up.
- The Aperture host URL (default:
http://ai) accessible from your device. Usehttp://, nothttps://. - OpenCode installed on your device.
To avoid unexpected TLS issues, use http:// for the Aperture URL when configuring LLM clients. All connections remain encrypted using WireGuard, even when HTTPS is not used.
Aperture routes requests based on the model name, not the LLM client. Any LLM client configured to use Aperture can access any provider your admin has set up. Refer to the provider compatibility reference for the full list of supported providers and API formats.
Configure OpenCode
OpenCode requires two configuration changes: set the base URL to point at Aperture, and provide a placeholder API key for each provider.
Set the base URL
Point OpenCode at your Aperture instance by setting the base URL for each provider in the OpenCode configuration file.
-
Open or create the OpenCode configuration file. The file is usually named
opencode.jsonand located in your home directory or the directory where you run OpenCode. Refer to the OpenCode configuration documentation for details. -
Add the following configuration to set Aperture as the base URL for your providers:
{ "$schema": "https://opencode.ai/config.json", "provider": { "anthropic": { "options": { "baseURL": "http://ai/v1" } }, "openai": { "options": { "baseURL": "http://ai/v1" } } } }Replace
http://aiwith your Aperture hostname. If you connect through ts-unplug, usehttp://localhost:<PORT_NUMBER>instead.Include only the providers you have configured in Aperture. For example, if you only have Anthropic configured, omit the
openaiblock. -
Save the file.
Configure authentication
OpenCode requires an authentication entry for each provider. Set a placeholder value for each provider you configured.
Aperture identifies users through Tailscale identity and injects the real API credentials when forwarding requests. The placeholder value is never sent to the provider.
-
Open or create the OpenCode authentication file.
-
Add the following placeholder keys:
{ "anthropic": { "type": "api", "key": "-" }, "openai": { "type": "api", "key": "-" } }The dash character (
-) satisfies OpenCode's authentication check. -
Save the file.
Alternatively, enter the placeholder key interactively by running /connect inside OpenCode and selecting Manually enter an API Key for each provider.
Verify the connection
- Send a test message in OpenCode.
- Open the Aperture dashboard at
http://ai/ui/and confirm the request appears on the Logs page.
If the request does not appear, refer to the Aperture troubleshooting guide.
Next steps
- Grant model access to users: Control which models each user or group can access through Aperture.
- View your usage dashboards: Monitor token consumption, costs, and session activity across your organization.
- Set per-user spending limits: Configure quota buckets to control costs for individual users.