Skip to content
This repository was archived by the owner on Jul 27, 2026. It is now read-only.
This repository was archived by the owner on Jul 27, 2026. It is now read-only.

feat(settings/agent): provider-driven Authentication section for ACP agents #2140

Closed

Description

@simonrosenberg

Problem

ACP agents authenticate either via local subscription/OAuth files (e.g. ~/.config/codex, ~/.claude) or via environment variables (ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, OPENAI_API_KEY, GEMINI_API_KEY, ...). Today, when a user wants the env-var path, the only place to set those values is the global Secrets page — which exists to inject env vars for tools the agent invokes (e.g. GitHub CLI access), not to authenticate the agent itself. Conflating the two is confusing, and the path from "I picked Claude Code on /settings/agent" to "I need to go to a different page and create a secret named exactly ANTHROPIC_API_KEY" is non-obvious.

Proposal

On /settings/agent, when ACP is enabled and a known provider is selected, render an Authentication block right after the Command + Model controls. Reuse the SDK fields that already exist on ACPAgentSettings — do not invent a new acp_env-shaped UI or a Canvas-side auth_fields registry.

Storage model: reuse ACPAgentSettings.llm

The SDK already does the work:

  • ACPAgentSettings.llm: LLM exists for cost/metrics attribution and carries api_key: SecretStr and base_url: str | None (openhands-sdk/openhands/sdk/settings/model.py).
  • ACPAgentSettings.resolve_provider_env() already translates llm.api_key / llm.base_url into the provider-native env vars (ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, ...) by reading api_key_env_var / base_url_env_var off the SDK provider registry (openhands-sdk/openhands/sdk/settings/acp_providers.py).
  • LLM.api_key already round-trips through the cipher (pydantic_secrets.serialize_secret / validate_secret) — same path LLM profiles use in production.

So: write agent_settings_diff.llm.api_key / agent_settings_diff.llm.base_url. Nothing else needs to change in the backend.

The raw ACPAgentSettings.acp_env field stays as an undocumented escape hatch for power users / custom commands, but is not rendered in this UI. (Side note: acp_env currently has a serializer but no field_validator for decryption, so it does not round-trip encrypted values today. Not blocking — we just avoid persisting credentials through it.)

Field visibility: derived from the SDK registry, not a new Canvas-side schema

Field rendering is driven by api_key_env_var / base_url_env_var on the SDK registry, mirrored to Canvas via @openhands/typescript-client (the same path acp-providers-sync.yml already enforces). Per-provider opt-outs for Base URL (e.g. Gemini, where Vertex proxy is unusual) live on the SDK side as a small additional flag mirrored down, not as a parallel Canvas-side auth_fields registry.

Provider API Key field Base URL field
Claude Code yes (ANTHROPIC_API_KEY) yes (ANTHROPIC_BASE_URL)
Codex yes (OPENAI_API_KEY) yes (OPENAI_BASE_URL)
Gemini yes (GEMINI_API_KEY) hidden (unusual path)
Custom hidden hidden

UX

  • Labels are user-facing: "API Key", "Base URL" — not ANTHROPIC_API_KEY.
  • Helper text under each field surfaces the env var name: "Sets ANTHROPIC_API_KEY when the agent launches."
  • Block-level helper text: "Leave blank to use local subscription auth via the provider's config files."
  • API Key field follows the LLM-profile editor pattern: don't round-trip the encrypted secret into the form — render a "configured" state and let the user replace it. The GET response already has llm_api_key_is_set to gate the initial state.
  • External env detection. Add acp_provider_api_key_in_env: bool to SettingsResponse (server inspects os.environ.get(api_key_env_var)). When true and llm.api_key is empty, show "Using environment variable" instead of "unset".

Save-path changes (Canvas)

Extend buildAcpAgentSettingsDiff in src/constants/acp-providers.ts:

  • Accept apiKey?: string | null and baseUrl?: string | null and patch llm.api_key / llm.base_url into the diff.
  • Reset credentials on provider switch. When acp_server changes from the loaded value, set llm.api_key: null and llm.base_url: null so an OpenAI key doesn't linger after Codex → Claude Code. Mirrors the existing acp_args: [] reset.

Explicitly NOT in scope

  • No duplication with global Secrets. ACP auth lives on the agent block. Global Secrets keeps its existing role (env vars for tools the agent invokes). No syncing, no shortcut writes.
  • No migration. Feature is not yet in production.
  • Custom preset has no auth fields rendered: users running their own command set their own env in the command itself.
  • No acp_env UI in this PR. Stays as a backend escape hatch.

Open questions — resolved

  • External env detection → handled via acp_provider_api_key_in_env on SettingsResponse.
  • Provider-switch credential bleed-through → handled by extending buildAcpAgentSettingsDiff to null out llm.api_key / llm.base_url when acp_server changes.
  • Mid-conversation provider/model switch (PR feat(acp): inline live model picker for ACP conversations (#769) #832) → not applicable. The ACP subprocess inherits env at spawn; set_session_model only swaps the model identifier on a live session and doesn't touch env. Credential changes take effect on next conversation start; document in the helper text.

Related

Activity

  1. simonrosenberg commented on Jul 10, 2026

    @simonrosenberg
    MemberAuthor

    Implemented, with the final storage design differing from this early proposal. Current main has the shared provider-driven AcpCredentialsSection in the Agent settings/profile editor and onboarding; it writes provider credentials through the global Secrets channel rather than ACPAgentSettings.llm. The Agent Profile integration shipped in #1571.

  2. transferred this issue fromOpenHands/OpenHandson Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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