Repository navigation
feat(settings/agent): provider-driven Authentication section for ACP agents #2140
Description
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: LLMexists for cost/metrics attribution and carriesapi_key: SecretStrandbase_url: str | None(openhands-sdk/openhands/sdk/settings/model.py).ACPAgentSettings.resolve_provider_env()already translatesllm.api_key/llm.base_urlinto the provider-native env vars (ANTHROPIC_API_KEY,ANTHROPIC_BASE_URL, ...) by readingapi_key_env_var/base_url_env_varoff the SDK provider registry (openhands-sdk/openhands/sdk/settings/acp_providers.py).LLM.api_keyalready 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_KEYwhen 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_setto gate the initial state. - External env detection. Add
acp_provider_api_key_in_env: booltoSettingsResponse(server inspectsos.environ.get(api_key_env_var)). When true andllm.api_keyis empty, show "Using environment variable" instead of "unset".
Save-path changes (Canvas)
Extend buildAcpAgentSettingsDiff in src/constants/acp-providers.ts:
- Accept
apiKey?: string | nullandbaseUrl?: string | nulland patchllm.api_key/llm.base_urlinto the diff. - Reset credentials on provider switch. When
acp_serverchanges from the loaded value, setllm.api_key: nullandllm.base_url: nullso an OpenAI key doesn't linger after Codex → Claude Code. Mirrors the existingacp_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_envUI in this PR. Stays as a backend escape hatch.
Open questions — resolved
- External env detection → handled via
acp_provider_api_key_in_envonSettingsResponse. - Provider-switch credential bleed-through → handled by extending
buildAcpAgentSettingsDiffto null outllm.api_key/llm.base_urlwhenacp_serverchanges. - 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_modelonly 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
- PR feat(acp): inline live model picker for ACP conversations (#769) #832 — inline ACP model picker; adds the
useChatInputModelStateplumbing and the/switch_acp_modelroute — this issue extends the same/settings/agentpage. - Issue Verification settings: basic/advanced view toggle is a silent no-op when confirmation_mode is off #2146 — Verification basic/advanced toggle (separate UX cleanup).
- PRs feat: verify LLM config before saving in settings and onboarding #823 / feat: verify LLM credentials before saving profiles #838 — "verify LLM credentials" work; the same
LLMshape this issue rides on naturally extends to a "Verify" button on the ACP Authentication block.
Activity
simonrosenberg commentedon Jul 10, 2026
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.