Skip to content

[FEATURE]: Support non-interactive API-key login via auth login #57492

Open

Description

@maharshi365

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Request

Support saving a provider API key through opencode auth login without any interaction. Proposed syntax:

opencode auth login anthropic --api-key "$ANTHROPIC_API_KEY"

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.

Activity

  1. opencode-agent commented on Oct 20, 2026

    @opencode-agent
    Contributor

    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.

    Related:

  2. Dante-dan commented on Oct 20, 2026

    @Dante-dan
    Contributor

    I can take this on. Would maintainers approve a first version with --key-stdin and --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_key

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions