# Connect OpenCode to aicharged.io

> OpenCode: a remote MCP server in opencode.json, with the key read from an environment variable.

## At a glance

| Kind | Sign-in | Platforms | Status | Verified |
|---|---|---|---|---|
| Terminal agents (CLI) | API key (Bearer), OAuth sign-in | macOS, Linux, Windows | works today | 2026-10-22 |

- MCP: `https://aicharged.io/api/v1/mcp`
- Docs: https://opencode.ai/docs/mcp-servers

## Recipe

Config file (`opencode.json`):

```json
{
  "mcp": {
    "aicharged": {
      "type": "remote",
      "url": "https://aicharged.io/api/v1/mcp",
      "enabled": true,
      "headers": {
        "Authorization": "Bearer {env:AICHARGED_API_KEY}"
      },
      "oauth": false
    }
  }
}
```

OpenCode fills in the env: reference from your environment; oauth: false stops it from starting an OAuth sign-in.

Store the key in an environment variable:

```sh
export AICHARGED_API_KEY="<API_KEY>"
```

Add the export line to your shell profile (e.g. ~/.zshrc) so new terminals see the key too.

Store the key in an environment variable — Windows (PowerShell):

```powershell
[Environment]::SetEnvironmentVariable("AICHARGED_API_KEY", "<API_KEY>", "User")
```

[Client documentation](https://opencode.ai/docs/mcp-servers)

## Authentication

- Send `Authorization: Bearer <API_KEY>` with every request. Create a key at https://aicharged.io/admin/account/api-keys.
- OAuth 2.1 (PKCE S256) is available for clients that cannot send a static key (ChatGPT).
- Without a key the endpoint answers 401 with a WWW-Authenticate header that points to https://aicharged.io/.well-known/oauth-protected-resource.

All 51 clients: https://aicharged.io/connect.md

HTML version: https://aicharged.io/connect/opencode
