docs/design/auth/motivation.md
The auth module used to model each setup path as a separate flow: API key,
OAuth, subscription plans, and custom providers. In practice, all of these paths
produce the same kind of output: updates to the user's provider configuration in
~/.qwen/settings.json.
This refactor makes provider setup the shared abstraction. A provider describes how it is shown, how credentials are collected, which models it installs, and which settings patch should be applied. API keys, OAuth, coding plans, token plans, and custom wizards are setup methods for a provider, not separate auth architectures.
/auth user-facing flows easy to understand:
ProviderInstallPlan and
applyProviderInstallPlan./auth; they should not drive settings logic.The new structure separates provider definitions, install logic, and UI state:
packages/cli/src/auth/
├── allProviders.ts
├── providerConfig.ts
├── types.ts
├── install/
│ └── applyProviderInstallPlan.ts
└── providers/
├── alibaba/
├── custom/
├── oauth/
└── thirdParty/
ProviderConfig is the declarative contract for built-in providers. It contains
the provider label, protocol, base URL options, environment key, model list,
model metadata, UI grouping, and setup behavior.
buildInstallPlan converts a provider config and collected setup inputs into a
ProviderInstallPlan. The install plan is the only object the settings writer
needs to understand.
applyProviderInstallPlan applies that plan by updating environment settings,
modelProviders, selected auth type, optional model selection, and provider
metadata. This keeps settings persistence independent from the UI flow that
collected the inputs.
/auth can still present different entry points, but they should all converge on
the same provider install path:
Alibaba ModelStudio
Third-party Providers
https://api.z.ai/api/coding/paas/v4https://api.z.ai/api/paas/v4OAuth
Custom Provider
Static built-in providers can persist provider metadata under
providerMetadata.<providerId>, including the model list version and base URL.
This lets Qwen Code detect when a provider's built-in model list changes and
prompt the user to update owned models without overwriting unrelated custom
models.
Custom providers are different: their model list is user-authored and should not be treated as an auto-updatable built-in model list.