docs/zai.md
z.ai is API-token based. No browser cookies.
~/.config/codexbar/config.json or legacy ~/.codexbar/config.json → providers[].apiKey).Z_AI_API_KEY.~/.config/codexbar/config.json~/.codexbar/config.jsonCODEXBAR_CONFIG=/path/to/config.jsonSet API region to Global (api.z.ai) or BigModel CN (open.bigmodel.cn).
UI: Settings → Providers → z.ai. For team usage, add a token account, turn on Team mode, then enter the API key, Organization ID, and Project ID.
CLI personal:
printf '%s' "$Z_AI_API_KEY" | codexbar config set-api-key --provider zai --stdin
CLI team:
printf '%s' "$Z_AI_API_KEY" | codexbar config set-api-key --provider zai --stdin \
--label Team \
--usage-scope team \
--organization-id org_... \
--workspace-id proj_...
Check:
codexbar config validate
codexbar usage --provider zai --account Team
Personal config can use providers[].apiKey. Team config uses tokenAccounts:
{
"id": "zai",
"enabled": true,
"region": "bigmodel-cn",
"tokenAccounts": {
"version": 1,
"activeIndex": 0,
"accounts": [
{
"id": "00000000-0000-0000-0000-000000000001",
"label": "Team",
"token": "<z.ai API key>",
"addedAt": 0,
"lastUsed": null,
"usageScope": "team",
"organizationId": "org_...",
"workspaceID": "proj_..."
}
]
}
}
Keep organizationId and workspaceID single-line. Do not paste display names, URLs, or multiple IDs.
For BigModel China team usage, CodexBar needs the Bigmodel-Organization and Bigmodel-Project request headers:
https://bigmodel.cn/usercenter/proj-mgmt/apikeyshttps://open.bigmodel.cn/usercenter/apikeys.https://bigmodel.cn/coding-plan/team/usage-statsapi/monitor/usage/quota/limit or api/monitor/usage/model-usage. Copy these request headers:
Bigmodel-Organization → organizationIdBigmodel-Project → workspaceIDCopy each value once, on one line. Multi-line or duplicated IDs can make the API return data: {}, leaving MCP,
5-hour, and hourly usage empty.
GET https://api.z.ai/api/monitor/usage/quota/limithttps://open.bigmodel.cnZ_AI_API_HOST=open.bigmodel.cn.Z_AI_QUOTA_URL=https://open.bigmodel.cn/api/coding/paas/v4.http:// overrides fail closed before the bearer token is attached to a request. If both z.ai overrides are set,
Z_AI_QUOTA_URL has priority for quota requests; a stale lower-priority Z_AI_API_HOST is ignored for that quota
path, but direct model-usage requests still validate Z_AI_API_HOST before sending bearer auth.authorization: Bearer <token>accept: application/jsonusageScope: team is queried as team usage.usageScope: teamorganizationId: BigModel organization idworkspaceID: BigModel project idtype=2; team hourly model usage appends type=3. Both send the BigModel selectors:
Bigmodel-Organization: <org id>Bigmodel-Project: <project id>https://z.ai/manage-apikey/coding-plan/personal/my-planhttps://bigmodel.cn/coding-plan/personal/usagehttps://bigmodel.cn/coding-plan/team/usage-statsdata.limits[] → each limit entry.data.planName (or plan, plan_type, packageName) → plan label.TOKENS_LIMIT → primary (tokens window).TIME_LIMIT → secondary (MCP/time window) if tokens also present.nextResetTime (epoch ms) → date.usageDetails[] per model (MCP usage list).Sources/CodexBarCore/Providers/Zai/ZaiUsageStats.swiftSources/CodexBarCore/Providers/Zai/ZaiSettingsReader.swiftSources/CodexBar/ZaiTokenStore.swift (legacy migration helper)