# provider-targets

Provider-target resolver and Cradle-owned runtime preference API.

- `index.ts`: HTTP routes for reading and updating provider-target model settings, Claude Agent model matrix defaults, model visibility, custom model IDs, provider-target auth diagnostics, provider-target scoped Codex account diagnostics, and Codex WHAM diagnostics.
- `model.ts`: Elysia request and response schemas for provider-target preference, Claude Agent matrix, auth diagnostics, and diagnostics routes.
- `service.ts`: Resolves a runtime provider target into normalized config, credential, and ownership-aware metadata for manual profiles and external provider records; writes Cradle-owned `connection_config_json.claudeAgent.modelAliases`; disables bound agents when a provider target becomes disabled.

Manual profiles and external runtime targets both implement the provider-target contract. External source records remain source-owned; model visibility, custom model IDs, and Claude Agent haiku / sonnet / opus model aliases are Cradle-owned runtime preferences written to the runtime target namespace. Model registry mappings are global and owned by `modules/model-registry`, not by any target.
Provider target availability is a launch prerequisite for provider-backed agents. Turning a provider target off preserves the target record and its preferences, but forces every bound agent to disabled until the user reselects or re-enables an available provider target.
Deleting a provider target detaches chat-owned historical rows from the removed target instead of deleting sessions or messages. Bound agents are retained, disabled, and detached from the missing target so their identities can be repaired without losing chat attribution.
Codex account diagnostics are exposed as provider-target scoped Settings APIs under `/provider-targets/:providerTargetId/codex/*`. The routes read Codex-native account identity, auth-required state, usage, rate-limit state, and WHAM usage/reset-credit/referral diagnostics only after an explicit user action in Settings; auth tokens are never projected into the diagnostics response. Unsupported targets return an unsupported diagnostics response without starting Codex app-server or calling WHAM, while reset-credit consumption is a separate POST action with an idempotency key.
Provider target auth diagnostics are exposed under `/provider-targets/:providerTargetId/auth-diagnostics`. The route reads runtime-owned authentication status without projecting secret values. Claude Agent supports both API key mode and official Claude subscription mode: API key mode checks only for configured credential presence, while official mode clears inherited Anthropic API credentials, removes only Cradle-owned Claude config-dir overrides, probes the Claude CLI against the user's Claude login state, parses `claude auth status`, and falls back to Claude Agent SDK account metadata when the CLI status omits subscription type.
