You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Support non-interactive API-key login via auth login #57492
A positional form, opencode auth login <provider> <apikey>, would also work.
Current behavior
In V2, selecting --method key still requires an interactive terminal to enter the secret. Environment credentials work, but do not create saved provider accounts.
Use case
Provision saved credentials from CI, dev containers, and automated setup scripts without a TUI, browser, or terminal prompt.
Expected behavior
Accept the supplied key and select API-key authentication without a picker.
Save the key as a provider account through the existing flow.
Preserve interactive entry when no key is supplied.
Reject empty keys and providers without API-key authentication.
Reuse existing --answer key=value options for provider-specific forms.
Do not print the key in command output.
Keys supplied as arguments can appear in shell history and process listings. A stdin option would be a useful safer alternative, but is not required for the minimal feature.
Possible implementation
Add an optional key input in packages/cli/src/commands/commands.ts and pass it through packages/cli/src/commands/handlers/auth/login.ts. Use the supplied key instead of the interactive secret prompt, then call the existing client.integration.connect.key(...) API. No server or database change appears necessary.
Add regression tests for noninteractive login, invalid keys, unsupported providers, and the existing interactive fallback.
Related work
The same feature was requested in #15725, which was closed automatically after inactivity. Its closure comment asks users to open a new issue if the request remains relevant. This is a follow-up because the capability is still missing.
PR #14470 added options to skip provider/method selection, but did not add noninteractive API-key input.
Thanks for the detailed request! In short, you'd like opencode auth login <provider> to accept an API key without a prompt, e.g. opencode auth login anthropic --api-key "$ANTHROPIC_API_KEY" (ideally with a stdin option too). That way CI, dev containers and setup scripts can save provider credentials without a terminal prompt.
You're right that in v2 the API-key method always asks for the key in an interactive terminal, so this would be a new option. Maintainers will consider it.
In the meantime, a partial workaround is to save the credentials once on a machine where you can enter them interactively, then copy them over: opencode auth export > creds.json there, and opencode auth import < creds.json (or opencode auth import creds.json) in the container or CI job. That file contains secrets, so handle it like one.
In current V2, keyLogin always calls secret() before the existing integration.connect.key({ integrationID, key, answer, location }) request. I would keep that connection path and change only the CLI input handling:
Require an existing integration ID/name; either input option selects its key method. Reject conflicting options, explicit non-key methods, unsupported providers, missing environment variables, and empty/whitespace-only keys. Keep interactive behavior when neither option is given. Leave well-known URL discovery outside this first noninteractive path so failed validation cannot add provider configuration.
Stdin must be redirected, read once to EOF with a size bound, remove only one final LF/CRLF, and reject embedded newlines. The env option reads the named variable, not a secret argument; CI environments still need normal secret handling.
Reuse --answer validation/defaults, but fail on missing required or external-interaction fields instead of prompting/opening a browser in this mode. Validate everything before the single connect request; do not write credential/config files directly or introduce a delete-then-replace flow.
Report success only after persistence succeeds; retain exit 1 for errors and 130 for cancellation. Never echo key input, including on errors. Saving a credential is not proof the provider accepts it.
Tests would cover piped stdin and env persistence, option/method conflicts, malformed/empty input, provider form validation, no mutation on validation failure, persistence failure preserving existing accounts, output redaction, and interactive fallback. #14470 covers selector skipping; this would fill the remaining secret-input gap raised in #15725.
Activity
opencode-agent commentedon Oct 20, 2026
Thanks for the detailed request! In short, you'd like
opencode auth login <provider>to accept an API key without a prompt, e.g.opencode auth login anthropic --api-key "$ANTHROPIC_API_KEY"(ideally with a stdin option too). That way CI, dev containers and setup scripts can save provider credentials without a terminal prompt.You're right that in v2 the API-key method always asks for the key in an interactive terminal, so this would be a new option. Maintainers will consider it.
In the meantime, a partial workaround is to save the credentials once on a machine where you can enter them interactively, then copy them over:
opencode auth export > creds.jsonthere, andopencode auth import < creds.json(oropencode auth import creds.json) in the container or CI job. That file contains secrets, so handle it like one.Related:
Dante-dan commentedon Oct 20, 2026
I can take this on. Would maintainers approve a first version with
--key-stdinand--key-env NAME, rather than an API key value in argv? For example:opencode auth login anthropic --key-env ANTHROPIC_API_KEY opencode auth login anthropic --key-stdin < /run/secrets/anthropic_api_keyIn current V2,
keyLoginalways callssecret()before the existingintegration.connect.key({ integrationID, key, answer, location })request. I would keep that connection path and change only the CLI input handling:--answervalidation/defaults, but fail on missing required or external-interaction fields instead of prompting/opening a browser in this mode. Validate everything before the single connect request; do not write credential/config files directly or introduce a delete-then-replace flow.Tests would cover piped stdin and env persistence, option/method conflicts, malformed/empty input, provider form validation, no mutation on validation failure, persistence failure preserving existing accounts, output redaction, and interactive fallback. #14470 covers selector skipping; this would fill the remaining secret-input gap raised in #15725.