auth-change

A guide for changing authentication in a command-line application, including API keys, access tokens, configuration, and request signing. It covers separate credentials for model APIs, a console service, and cloud APIs.

In plain words
What is it for?
Use it when adding a credential source, changing login or logout behavior, resolving multiple credentials, or injecting credentials into software development kits (SDKs).
Why use it?
It helps developers change login and credential handling without mixing credentials from different services or bypassing command-level access requirements.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/modelstudioai/cli/auth-change
Clone the repo
git clone --depth 1 https://github.com/modelstudioai/cli
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,667 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.03667
Opus 5 $0.00000 $0.01834
Sonnet 5 $0.00000 $0.00733
Haiku 4.5 $0.00000 $0.00367

Measured 2d ago against content hash e89c6cd133dd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

auth-change scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/agents/auth-change.md · 175 lines

How it starts

The opening of the file, as written. The whole thing — 175 lines — stays where its author put it; the contents beside it link to each section on GitHub.

鉴权扩展

触发条件

  • 增加新的鉴权域或 token 来源(env / config / flag / 文件)
  • 调整 API Key / Console token 解析优先级
  • bl auth login / auth status / auth logout 流程
  • 改 runtime 对 command auth 的 gating 或 credential 注入

鉴权链路

argv flags ─┐
env var   ──┼─ buildSources(flags) ─┐
config    ──┘                       │
                                    ├─ buildSettings(sources) → ctx.settings
                                    │
                                    ├─ resolveApiKey(sources)     → model-domain Client
                                    ├─ resolveConsole(sources)    → console-domain Client
                                    └─ resolveOpenApi(sources)    → OpenAPI Client

defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx)

当前 command 鉴权域(AuthRequirement):

  • apiKey — DashScope / OpenAI-compatible 模型域,用 API key 与 model base URL
  • console — Bailian Console Gateway,用 console access token + region/site/switchAgent;workspace_id 是独立的 Settings 作用域,不属于 credential
  • openapi — 阿里云 OpenAPI 签名域,用 AccessKey ID/Secret 调用 Token Plan 等 OpenAPI
  • none — 本地命令、登录/配置类命令、无需 credential 的命令

多凭证并存

~/.bailian/config.json 可同时保存 api_keyaccess_tokenaccess_key_*。登录任一种方式不得删除另一种:

  • bl auth login --api-key ... 更新 api_key;显式 base_url 会一并写入,所选命名 Profile 若命中内置套餐预设(当前为 token-plan),则在尚未保存 base_url 时补写预设地址,并把该预设的默认模型物化写入。API Key 落盘成功后,api_key_capabilities 保留已有项并追加当前 preset 中缺少的项,不自动删除任何已有能力;无 preset 的自定义 Profile 不做合并。登录仍不得删除其他鉴权域的凭证
  • bl auth login --console 只更新 access_token 以及回调携带的 console 作用域字段
  • bl auth login --open-api ... 更新 access_key_id / access_key_secret,同时会调用 OpenAPI 生成 CLI access_token 并一并写入;即一次 --open-api 登录同时产生 openapiconsole 域凭证
  • bl auth logout --console 只清 access_token
  • bl auth logout --open-api 只清 access_key_id / access_key_secret / security_token
  • bl auth logoutapi_key + base_url + access_token + access_key_*

解析分工:

  • resolveApiKey()auth: "apiKey" 命令;优先级 --api-key > DASHSCOPE_API_KEY > config api_key
  • resolveModelBaseUrl() — model base URL;优先级 --base-url > DASHSCOPE_BASE_URL > config base_url > REGIONS.cn,返回前统一归一化为 URL origin(仅保留协议、host 和显式端口,去除 path、query、fragment)
  • --config 只选择 config 文件 block,不提升该 block 的字段优先级。对 auth: "apiKey" 命令,runtime 会先按叶子命令路径检查所选 Profile 的 api_key_capabilities:
    • --api-key / --base-urlDASHSCOPE_API_KEY / DASHSCOPE_BASE_URL 任一显式连接覆盖存在时,完全跳过自动降级,继续走统一的 flag > env > selected config file > 默认值
    • 配置文件显式声明 api_key_capabilities 后,命中能力时保留所选 Profile,未命中时仅把 file-backed api_key / base_url 来源切到顶层 default,其他 Settings 仍来自所选 Profile
    • 字段缺失时不启用降级,包括命中内置套餐预设的 Profile;preset 只在 API Key 登录落盘成功后物化写入,升级 preset 需要重新登录
    • fallback 反馈写 stderr:text 模式输出本地化句子,--output json 输出两空格缩进的多行 warning 对象;若后续鉴权失败,warning 与多行 error 对象以空行分隔,stdout 仍只保留命令结果
  • 显式 auth login --config <name> 在凭证落盘成功后自动激活目标 Profile;未传 --config 时继续写当前激活项,失败和 dry-run 不切换
  • resolveConsole()auth: "console" 命令;当前 token 来自 config access_token,region/site/switchAgent 来自 flag > config > 默认
  • resolveOpenApi()auth: "openapi" 命令;优先级 --access-key-id/--access-key-secret > ALIBABA_CLOUD_ACCESS_KEY_ID/ALIBABA_CLOUD_ACCESS_KEY_SECRET > config access_key_*。兼容读取旧字段 openapi_access_key_*,新写入只写短字段
  • describeAuthState()auth status / banner / telemetry 使用的只读快照

Read the full file on GitHub · 175 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 175 lines · 0 tokens per session scan A e89c6cd133dd

Subscribe to this mod's changes

auth-change is an agent published in the GitHub repository modelstudioai/cli (320 stars, last pushed 4d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 3,667 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.