Use OpenCode with Aperture

Last validated:

Aperture by Tailscale is currently in alpha.

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. Use http://, not https://.
  • 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.

  1. Open or create the OpenCode configuration file. The file is usually named opencode.json and located in your home directory or the directory where you run OpenCode. Refer to the OpenCode configuration documentation for details.

  2. 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://ai with your Aperture hostname. If you connect through ts-unplug, use http://localhost:<PORT_NUMBER> instead.

    Include only the providers you have configured in Aperture. For example, if you only have Anthropic configured, omit the openai block.

  3. 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.

  1. Open or create the OpenCode authentication file.

  2. Add the following placeholder keys:

    {
      "anthropic": {
        "type": "api",
        "key": "-"
      },
      "openai": {
        "type": "api",
        "key": "-"
      }
    }
    

    The dash character (-) satisfies OpenCode's authentication check.

  3. 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

  1. Send a test message in OpenCode.
  2. 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