Skip to main content

ChatCRS

ChatCRS 是 ChatArch 的 CRS 管理 CLI。外部管理面优先使用 CRS HTTP/Admin API;service 域是 server-local surface,只在 CRS 服务器本机 shell 里操作本机 CRS checkout / Node runtime / crs executable。

Images 验收、debug runtime、Nginx/edge、release/cutover 等花哨/任务型能力不作为当前包内命令暴露;这些属于代理站维护、专项验收或运维 runbook,后续需要时单独设计。

安装与开发

python -m pip install -e '.[dev,docs]'
chatcrs --help
chatcrs --version
python -m pytest -q
python -m mkdocs build --strict
python -m build

完整文档使用 MkDocs,本地预览:

python -m mkdocs serve

线上文档:https://arch.gh.wzhecnu.cn/ChatCRS/

配置测试

安装后用 chatenv paste --stdin --profile smoke -I --yes 导入 CRS_API_BASE(服务根 URL)与 CRS_API_KEY,再 chatenv use smoke -t crs -I、chatenv test -t crs -I。 默认只验证 Key 鉴权,明确不证明上游可用;显式配置可选 CRS_API_MODEL 后才发起同 Key 的 Codex Responses 流式文本请求(会产生用量)。失败非零,不打印凭据或原始错误。详见配置文档。

CLI 树

chatcrs
├── --help  # Show this message and exit.
├── --version  # Show the version and exit.
├── --tree  # Print the registered CLI tree and exit.
├── --tree-brief  # Print the registered CLI tree without parameter signatures and exit.
├── admin  # Remote CRS administrator operations via HTTPS Admin API.
│   ├── accounts  # Inspect or refresh remote CRS account state via HTTP Admin API.
│   │   ├── refresh-status [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] <ACCOUNT-ID> [--execute] [--json-output]  # Reset a CRS OpenAI account status after transient failures.
│   │   └── usage [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] [--json-output]  # List OpenAI/Codex account usage and scheduling metadata.
│   ├── keys  # Inspect remote CRS API keys with admin privileges.
│   │   ├── list [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] [--include-stats] [--time-range TIME-RANGE] [--json-output]  # List CRS API key metadata, optionally including usage stats.
│   │   └── show [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] <KEY-ID> [--include-stats] [--time-range TIME-RANGE] [--json-output]  # Show one CRS API key by id or name.
│   ├── login [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] [--save-token] [--json-output]  # Verify CRS admin login without printing the session token.
│   └── token  # Manage cached CRS admin session tokens in the ChatArch token store.
│       ├── clear [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] [--execute] [--json-output]  # Clear the cached CRS admin session token.
│       ├── refresh [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] [--json-output]  # Login and save a fresh CRS admin session token.
│       └── status [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--username USERNAME] [--password PASSWORD] [--admin-token ADMIN-TOKEN] [--timeout TIMEOUT] [--json-output]  # Show cached CRS admin token metadata without printing the token.
├── codex  # Direct OpenAI Codex account token and usage helpers.
│   ├── account [--profile PROFILE] [--access-token ACCESS-TOKEN] [--refresh] [--client-id CLIENT-ID] [--timeout TIMEOUT] [--json-output]  # Read a safe OpenAI Codex account summary from token claims and API probe.
│   ├── quota [--profile PROFILE] [--account-id ACCOUNT-ID] [--access-token ACCESS-TOKEN] [--refresh] [--client-id CLIENT-ID] [--model MODEL] [--timeout TIMEOUT] [--json-output]  # Run a profile-only Codex responses smoke and show quota headers.
│   ├── reset  # Inspect or explicitly redeem banked Codex resets without model requests.
│   │   ├── consume [--json-output] [--timeout TIMEOUT] [--base-url BASE-URL] [--profile PROFILE] [--request-id REQUEST-ID] [--execute]  # Plan or redeem one reset with a persisted receipt and GET readback.
│   │   └── list [--json-output] [--timeout TIMEOUT] [--base-url BASE-URL] [--profile PROFILE]  # Read available reset count and expirations; never refresh credentials.
│   ├── token  # Manage OpenAI OAuth tokens through the ChatEnv Codex token store.
│   │   ├── refresh [--profile PROFILE] [--refresh-token REFRESH-TOKEN] [--client-id CLIENT-ID] [--timeout TIMEOUT] [--json-output]  # Refresh an OpenAI OAuth access token without printing token values.
│   │   └── status [--profile PROFILE] [--json-output]  # Show cached OpenAI OAuth token metadata without printing tokens.
│   └── usage [--profile PROFILE] [--account-id ACCOUNT-ID] [--access-token ACCESS-TOKEN] [--refresh] [--client-id CLIENT-ID] [--timeout TIMEOUT] [--json-output]  # Read Codex usage and quota metadata directly from OpenAI.
├── health [--base-url BASE-URL] [--json-output]  # Verify the CRS /health endpoint.
├── key  # CRS API-key-only operations that do not require admin login.
│   └── info [--profile PROFILE] [--base-url BASE-URL] [--api-key API-KEY] [--timeout TIMEOUT] [--path INFO-PATH] [--json-output]  # Query CRS key-info using only a CRS API key.
└── service  # Local CRS service lifecycle commands for the current server.
    ├── install [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs install` on this server.
    ├── restart [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs restart` on this server.
    ├── start [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs start` on this server.
    ├── status [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--json-output]  # Execute local `crs status` on this server.
    ├── stop [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs stop` on this server.
    ├── switch-branch <BRANCH> [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs switch-branch <branch>` on this server.
    ├── update [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs update` on this server.
    └── update-pricing [--app-dir APP-DIR] [--crs-command CRS-COMMAND] [--timeout TIMEOUT] [--execute] [--json-output]  # Plan or execute local `crs update-pricing` on this server.

运行 chatcrs --tree 可从实际 Click 注册表回读带参数签名的命令树;chatcrs --tree-brief 保留命令节点和描述,但省略参数签名。两种模式都固定使用 canonical 根名 chatcrs。

HTTP/Admin 与 API key

chatcrs health --base-url https://crs.example.com --json-output
chatcrs admin login --profile admin --json-output
chatcrs admin login --profile admin --save-token --json-output
chatcrs admin token status --profile admin --json-output
chatcrs admin token refresh --profile admin --json-output
chatcrs admin token clear --profile admin --json-output
chatcrs admin token clear --profile admin --execute --json-output
chatcrs admin accounts usage --profile admin --json-output
chatcrs admin accounts refresh-status <account_id> --profile admin --json-output
chatcrs admin accounts refresh-status <account_id> --profile admin --execute --json-output
chatcrs admin keys list --profile admin --include-stats --json-output
chatcrs admin keys show <key_id_or_name> --profile admin --json-output
chatcrs key info --profile admin --json-output
chatcrs codex token status --profile default --json-output
chatenv token refresh Codex default
chatcrs codex account --profile default --json-output
chatcrs codex quota --profile default --json-output
chatcrs codex usage --profile default --json-output

Server-local service

这些命令应安装在目标 CRS 服务器上,并在该服务器本机执行:

chatcrs service status --app-dir /path/to/crs --json-output
chatcrs service update --app-dir /path/to/crs --json-output
chatcrs service update --app-dir /path/to/crs --execute --json-output
chatcrs service restart --app-dir /path/to/crs --execute --json-output

status 默认执行本机只读 crs status。其它 service mutation 默认 dry-run,需要 --execute 才执行。

配置

ChatCRS 使用 CRS ChatEnv profile 管理 CRS Admin/API 配置,并为 OpenAI 注册 OAuth token refresher 供 Codex direct 使用。Codex direct 的稳定 OAuth profile 来自 envs/Codex/<profile>.env,runtime token 来自 tokens/Codex/<profile>.json,持久刷新用 chatenv token refresh Codex <profile>。Codex profile 可设置非敏感 relay 字段:OPENAI_OAUTH_BASE_URL 覆盖 OAuth token/accounts upstream,CHATGPT_BACKEND_BASE_URL 覆盖 ChatGPT backend upstream。公开文档只描述字段类别,不写具体 secret 文件路径或 secret-bearing env key 名。

Canonical 字段类别:

HTTP base URL
caller API key
admin username
admin password
admin bearer/session token

Service-local 目标不进入第二套 ChatEnv namespace;用当前工作目录或 --app-dir / --crs-command 指定本机 checkout 和 executable。

敏感字段只应存在于 ChatEnv 或进程环境中,不进入命令行参数、文档、PR body 或日志输出。Profile 文件应使用 0600 权限。

生产安全

外部管理只能使用 HTTP/Admin API;没有 HTTP lifecycle 接口时,不用远端执行补洞。要么新增 CRS API/host-agent,要么在目标服务器本机运行 chatcrs service ...。

更多内容见:

  • docs/cli.md
  • docs/interfaces.md
  • docs/configuration.md
  • docs/production-maintenance.md

Codex 重置卡

chatcrs codex reset list 通过 GET /wham/rate-limit-reset-credits 查询可用次数与到期时间;不请求模型、不刷新 OAuth。chatcrs codex reset consume 默认只生成计划,必须同时提供持久化的 --request-id 和 --execute 才消费一张卡。请求前保存审计,之后 GET 读回;相同请求 ID 不重复发送,结果不明应人工核对,不要生成新 ID 盲重试。完整重置会改变自然重置时间,且不是购买 Credits。

chatcrs codex reset list --profile work --json-output
chatcrs codex reset consume --profile work --request-id one-reviewed-operation --json-output

如既有反代未提供重置路由,可用 --base-url 显式指定重置后端;它不改变该 profile 的 usage/auth base,也不会修改配置。服务使用 ChatGPT 后端接口,可能随上游变化,不等同于稳定的 OpenAI Platform 公共 API。Python 消费者使用 chatcrs.reset_credits.CodexResetClient、inspect_reset_credits 与 consume_reset_credit;客户端 consume(..., execute=True) 由调用者自己的策略和持久化去重保护。ChatGlance 的阈值策略不属于 ChatCRS。

Metadata

Release files for ChatCRS 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ChatCRS 0.3.3
File Size Uploaded
chatcrs-0.3.3.tar.gz 81.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ChatCRS 0.3.3
File Interpreter ABI Platform
chatcrs-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 118.6 kB

Release files / chatcrs-0.3.3.tar.gz

Download URL chatcrs-0.3.3.tar.gz
Size 81.7 kB
Tags Source
SHA-256 checksum
How to use checksums
388041ef56bb4f361cb561d4107bb4710a872b0b8a4e570590e3111de9416c7e
BLAKE2b-256 checksum
How to use checksums
d3198e62a57a919e49898d367a4898172576f8efe2f25c21f2932bca5749fc5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / chatcrs-0.3.3-py3-none-any.whl

Download URL chatcrs-0.3.3-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7291835ad34317a8839de060a8b70b66f7b592dbbb33be1f6dd789d652907cce
BLAKE2b-256 checksum
How to use checksums
e83be8d43f96b7457e9d10287624b94b3c620894cb7b3521a9a6f751118beaf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.5

2 release files

0.3.4

2 release files

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page