|
1 | 1 | --- |
2 | 2 | title: "Providers" |
| 3 | +description: "Connect provider accounts and manage credentials from the CLI and TUI." |
3 | 4 | --- |
| 5 | + |
| 6 | +Connect a provider in the TUI, then choose one of its models: |
| 7 | + |
| 8 | +```text |
| 9 | +/connect |
| 10 | +/models |
| 11 | +``` |
| 12 | + |
| 13 | +`/connect` lists the integrations available from the current server and project. Select a provider, choose an |
| 14 | +authentication method when it offers more than one, and follow the prompts. |
| 15 | + |
| 16 | +## TUI |
| 17 | + |
| 18 | +The TUI supports API keys, OAuth, and provider authentication commands. OAuth opens an authorization URL or shows a |
| 19 | +code to enter; press `o` to open the URL and `c` to copy the authorization details. |
| 20 | + |
| 21 | +```text |
| 22 | +/connect |
| 23 | +# Select OpenAI, then ChatGPT Pro/Plus (headless). |
| 24 | +``` |
| 25 | + |
| 26 | +Run `/connect` again to add another account. Selecting an already connected provider opens its account list, where you |
| 27 | +can activate, rename, or delete a saved account. |
| 28 | + |
| 29 | +## CLI |
| 30 | + |
| 31 | +Use `auth login` for the same provider methods without opening the TUI. With no provider argument, the command opens an |
| 32 | +interactive provider picker. |
| 33 | + |
| 34 | +```bash |
| 35 | +opencode2 auth login |
| 36 | +``` |
| 37 | + |
| 38 | +Pass an integration ID or name to skip the first picker. Use `--method key` to select API-key entry explicitly. |
| 39 | + |
| 40 | +```bash |
| 41 | +opencode2 auth login anthropic --method key |
| 42 | +``` |
| 43 | + |
| 44 | +Method IDs are provider-specific. Run the command without `--method` to see the available methods when a provider has |
| 45 | +more than one. |
| 46 | + |
| 47 | +```bash |
| 48 | +opencode2 auth login openai |
| 49 | +``` |
| 50 | + |
| 51 | +API-key entry and provider forms require an interactive terminal. OAuth methods that ask you to paste an authorization |
| 52 | +code also require one. |
| 53 | + |
| 54 | +## Methods |
| 55 | + |
| 56 | +OpenCode receives provider credentials through four integration methods: |
| 57 | + |
| 58 | +| Method | Behavior | |
| 59 | +| --- | --- | |
| 60 | +| API key | Prompts for a secret and saves it as a provider account. | |
| 61 | +| OAuth | Provides a browser URL, device code, or authorization-code prompt, then saves tokens and refreshes them when supported. | |
| 62 | +| Command | Runs a provider-supplied authentication command and saves its standard output as a key. | |
| 63 | +| Environment | Reads a supported variable from the server process without saving it. | |
| 64 | + |
| 65 | +Providers can add forms to API-key and OAuth methods for required details such as an Azure resource name or a GitHub |
| 66 | +Enterprise domain. The CLI and TUI render those forms before starting authentication. |
| 67 | + |
| 68 | +## Environment |
| 69 | + |
| 70 | +Set a provider's supported environment variable on the server process that runs model requests. For a one-off private |
| 71 | +server, pass it when starting standalone mode. |
| 72 | + |
| 73 | +```bash |
| 74 | +ANTHROPIC_API_KEY=sk-ant-... opencode2 --standalone |
| 75 | +``` |
| 76 | + |
| 77 | +For the shared background server, add the variable to its managed environment. This stops a running service; the next |
| 78 | +OpenCode command starts it with the new value. |
| 79 | + |
| 80 | +```bash |
| 81 | +opencode2 service set env ANTHROPIC_API_KEY sk-ant-... |
| 82 | +opencode2 auth list |
| 83 | +``` |
| 84 | + |
| 85 | +Environment connections appear in `auth list` with type `environment`. They are not accounts: `auth logout` cannot |
| 86 | +remove them, so unset the variable to disconnect. A saved account takes precedence over an environment connection for |
| 87 | +the same integration. |
| 88 | + |
| 89 | +```bash |
| 90 | +opencode2 auth list |
| 91 | +opencode2 service unset env ANTHROPIC_API_KEY |
| 92 | +``` |
| 93 | + |
| 94 | +Some cloud providers also use their native ambient credential chain instead of an API-key variable: |
| 95 | + |
| 96 | +- Amazon Bedrock supports the AWS default credential chain, including profiles, access-key environments, web identity, |
| 97 | + and container credentials. It also supports `AWS_BEARER_TOKEN_BEDROCK`. |
| 98 | +- Google Vertex uses Application Default Credentials and a resolvable project. For example, authenticate with |
| 99 | + `gcloud auth application-default login` and set `GOOGLE_CLOUD_PROJECT`. |
| 100 | +- Azure exposes **Microsoft Entra ID (Azure CLI)** as a connect method when `az` is installed. Run `az login` first, then |
| 101 | + select that method in `/connect` or `auth login azure`. |
| 102 | + |
| 103 | +```bash |
| 104 | +gcloud auth application-default login |
| 105 | +GOOGLE_CLOUD_PROJECT=my-project opencode2 |
| 106 | +``` |
| 107 | + |
| 108 | +See [Providers](/providers) for provider-specific and server-side setup. |
| 109 | + |
| 110 | +## Accounts |
| 111 | + |
| 112 | +Each successful API-key, OAuth, or command login creates a saved account. The newest account becomes active; switch the |
| 113 | +active account by its label or credential ID. |
| 114 | + |
| 115 | +```bash |
| 116 | +opencode2 auth list |
| 117 | +opencode2 auth switch anthropic work |
| 118 | +``` |
| 119 | + |
| 120 | +Remove a saved account with `auth logout`. Both commands open pickers when their arguments are omitted. |
| 121 | + |
| 122 | +```bash |
| 123 | +opencode2 auth logout anthropic work |
| 124 | +``` |
| 125 | + |
| 126 | +In the TUI, `/connect` provides the same add, activate, rename, and delete operations for saved accounts. |
| 127 | + |
| 128 | +## Storage |
| 129 | + |
| 130 | +Saved API keys and OAuth tokens live in the server's SQLite database. For the local server, print its database path with: |
| 131 | + |
| 132 | +```bash |
| 133 | +opencode2 debug paths db |
| 134 | +``` |
| 135 | + |
| 136 | +The usual release path is `~/.local/share/opencode/opencode.db`; `XDG_DATA_HOME`, the release channel, and `OPENCODE_DB` |
| 137 | +can change it. Do not edit the database to manage credentials; use `/connect` or the `auth` commands. |
| 138 | + |
| 139 | +V2 imports supported credentials from the legacy `auth.json` in the OpenCode data directory during its database |
| 140 | +migration. New and updated credentials are stored in SQLite rather than written back to that file. |
0 commit comments