| summary | z.ai provider data sources: API token in config/env and quota API response parsing. | ||
|---|---|---|---|
| read_when |
|
z.ai is API-token based. No browser cookies.
- Config token (
~/.config/codexbar/config.jsonor legacy~/.codexbar/config.json→providers[].apiKey). - Environment variable
Z_AI_API_KEY.
- New installs:
~/.config/codexbar/config.json - Legacy installs:
~/.codexbar/config.json - Override for scripts/tests:
CODEXBAR_CONFIG=/path/to/config.json
Set 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:
- Open the BigModel API-key page and create/copy the API key:
https://bigmodel.cn/usercenter/proj-mgmt/apikeys- Some accounts still redirect through
https://open.bigmodel.cn/usercenter/apikeys.
- Open the team usage dashboard:
https://bigmodel.cn/coding-plan/team/usage-stats
- Select the organization/team and project to track.
- Open browser DevTools → Network, refresh the team usage page, and inspect the
request to
api/monitor/usage/quota/limitorapi/monitor/usage/model-usage. Copy these request headers:Bigmodel-Organization→organizationIdBigmodel-Project→workspaceID
Copy 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/limit- BigModel (China mainland) host:
https://open.bigmodel.cn - Override host via Providers → z.ai → API region or
Z_AI_API_HOST=open.bigmodel.cn. - Override the full quota URL (e.g. coding plan endpoint) via
Z_AI_QUOTA_URL=https://open.bigmodel.cn/api/coding/paas/v4. - Endpoint overrides must be explicit HTTPS URLs or bare hosts/paths that CodexBar normalizes to HTTPS. Explicit
http://overrides fail closed before the bearer token is attached to a request. If both z.ai overrides are set,Z_AI_QUOTA_URLhas priority for quota requests; a stale lower-priorityZ_AI_API_HOSTis ignored for that quota path, but direct model-usage requests still validateZ_AI_API_HOSTbefore sending bearer auth. - Headers:
authorization: Bearer <token>accept: application/json
- The default usage scope is personal. Only a token account with
usageScope: teamis queried as team usage. - Each z.ai token account can enable Team mode via UI, CLI, or config. Team accounts store:
usageScope:teamorganizationId: BigModel organization idworkspaceID: BigModel project id
- Team quota scope appends
type=2; team hourly model usage appendstype=3. Both send the BigModel selectors:Bigmodel-Organization: <org id>Bigmodel-Project: <project id>
- Live API checks return success with empty limits when one of the selectors is missing, so CodexBar treats both Organization ID and Project ID as required for team usage.
- Global:
https://z.ai/manage-apikey/coding-plan/personal/my-plan - BigModel China:
https://bigmodel.cn/coding-plan/personal/usage - BigModel China team:
https://bigmodel.cn/coding-plan/team/usage-stats - CodexBar's Usage Dashboard action follows the configured API region.
- Response fields:
data.limits[]→ each limit entry.data.planName(orplan,plan_type,packageName) → plan label.
- Limit types:
TOKENS_LIMIT→ primary (tokens window).TIME_LIMIT→ secondary (MCP/time window) if tokens also present.
- Window duration:
- Unit + number → minutes/hours/days.
- Reset:
nextResetTime(epoch ms) → date.
- Usage details:
usageDetails[]per model (MCP usage list).
Sources/CodexBarCore/Providers/Zai/ZaiUsageStats.swiftSources/CodexBarCore/Providers/Zai/ZaiSettingsReader.swiftSources/CodexBar/ZaiTokenStore.swift(legacy migration helper)