Account Management API
Accounts form a tree: every account has a parent (PID) and a lineage path (DNA). Management endpoints act only on your own subtree. For concepts, see Account Hierarchy.
export BASE_URL="https://api.xairouter.com"
export API_KEY="sk-Xvs..." # key of a manager accountEndpoints
| Method and path | Permission | Description |
|---|---|---|
POST /x-users | Manager with remaining sub-account quota | Create a direct sub-account |
GET /x-users, GET /x-users/{identifier} | Manager | Query direct sub-accounts |
GET /x-dna, GET /x-dna/{identifier} | Manager | Query all descendant accounts |
PUT /x-users/{identifier} (or POST) | Manager; the account itself may update some profile fields | Update an account |
POST /x-users/batch-credit | Manager | Grant or reclaim credit in batches |
DELETE /x-users/{identifier} | Manager | Delete a descendant account |
POST /x-self | Any account | Rotate your own API Key |
POST /x-news/{target}, DELETE /x-news/{target} | Manager | Publish or delete notices for descendant accounts |
Manager: sub-account capability (user_limit above 0 or existing sub-accounts), daily token limit above 800000000, and a balance above the management threshold. Otherwise the response is 403 and the body names the missing condition, for example Management access requires balance above 100.00.. The manage field of GET /dashboard/status lets you check beforehand, and user_api_balance gives the balance threshold.
Field names: request bodies use PascalCase field names (such as CreditGranted and AllowModels). The update endpoint returns 400 Unknown field: X for unknown fields; most known fields with the wrong case or type are silently ignored (CreditGranted and DryRun are exceptions and return 400), so follow this page exactly.
Create a sub-account
curl -X POST "$BASE_URL/x-users" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"Email": "[email protected]",
"Name": "dev-a",
"Alias": "Dev A",
"CreditGranted": 20,
"RPM": 60,
"TPM": 200000
}'| Field | Required | Description |
|---|---|---|
Email | Yes | Login and notification email, globally unique, at most 128 bytes |
Name | No | Account name, globally unique; 2 to 63 bytes of letters, digits, _, and -, with at least one letter. Generated when omitted |
Alias | No | Display name, same rules as Name; derived from the email when invalid |
BillingEmail | No | Billing email; several allowed (separated by ,, ;, or whitespace, total length at most 256); defaults to Email |
CreditGranted | No | Initial credit (priced as the sub-account), at least the minimum starting credit (user_min_balance in /dashboard/status); the minimum is granted even when omitted |
Rates | No | Price multiplier, max(requested value, your Rates) |
RPM, RPH, RPD, TPM, TPH, TPD | No | Account-level rate limits, each min(requested value, your value); inherit your value when omitted or below 1 |
UserLimit | No | Number of sub-accounts this sub-account may create; default 0. Forced to 0 when your own UserLimit is below 64 |
SecretKey | No | Specify the sub-account's key (must be a valid 51-character sk-Xvs key); generated when omitted |
These attributes are inherited from you and have no effect when passed at creation; adjust them after creation through the update endpoint: DailyLimit, Resources, AllowIPs, AllowModels, AllowLevels, ModelLimits, ModelMapper. HardLimit and SoftLimit are computed from the initial balance. A sub-account's Level, Gear, Role, and price factor always follow yours.
Credit source: the initial credit is transferred from your balance. Your balance is reduced by CreditGranted รท child.Rates ร your Rates, and the sub-account's credit keeps the expiry of the source credit. An insufficient balance returns 403 Insufficient balance.
Response (200):
{
"Action": "add",
"User": {
"ID": 123,
"SecretKey": "sk-Xvs...",
"Updates": {"Name": "dev-a", "Level": 1, "Rates": 1, "CreditBalance": [], "UserLimit": 0}
}
}SecretKey is returned only once, in the creation response, and is also sent to the sub-account's Email in a welcome email. Store it safely.
| Status | Body | Reason |
|---|---|---|
400 | Invalid email address | Invalid email |
400 | Name: 4-63 chars, at least 1 letters | Invalid account name (the actual lower bound is 2 bytes) |
403 | Sub-user limit reached / Management access requires remaining sub-user quota. | Sub-account quota exhausted |
403 | Insufficient balance | Not enough balance to transfer |
409 | User already exists | The account name or email is already used |
Query accounts
GET /x-users # direct sub-accounts
GET /x-dna # all descendants
GET /x-dna?level=2&page=1&size=50&order=desc
GET /x-users/42 # by ID
GET /x-dna/[email protected] # by email
GET /x-dna/.1.5. # by DNA prefix
GET /x-dna/L2 # all Level 2 descendantsQuery parameters (for /x-users and /x-dna themselves only):
| Parameter | Description |
|---|---|
id, name, email, level | Exact match |
dna | DNA prefix match |
page, size | Pagination; at most 8192 per page |
order | desc (or id_desc) sorts by ID descending, anything else ascending |
Path identifiers (/x-users/{identifier}, /x-dna/{identifier}): a number is an ID; one containing @ is an email; one starting with . is a DNA prefix; L<n>, G<n>, R<n>, T<n>, F<x> filter by Level, Gear, Role, Tier, and Factor; anything else is an account name.
Response: always an array of account objects, [] when nothing matches. SecretKey, PublicKey, PartialKey, and EncryptionKey are masked as "*". The response headers include X-Total-Count, plus X-Page, X-Per-Page, and X-Total-Pages when paginated.
Every call to GET /x-users or GET /x-dna incurs one management call fee (0.012 USD by default).
Update an account
curl -X PUT "$BASE_URL/x-users/dev-a" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"CreditGranted": 10,
"Days": 90,
"DailyLimit": 50,
"AllowModels": "gpt-6* claude-sonnet-5-5",
"AllowIPs": "203.0.113.0/24"
}'Locating the target: /x-users/{identifier} or /x-users?id=..., /x-users?name=.... A numeric ID is looked up globally and then checked to be your descendant; account names and emails are looked up among your descendants only. A target outside your subtree returns 403 Forbidden (numeric ID) or 404 User not found.
Updatable fields
| Field | Who can set it | Description |
|---|---|---|
Email, Alias, BillingEmail, QRCode | Manager; the account itself | Profile |
InvoiceInfo | The account itself only | Invoice details {type, company_name, tax_no, registered_address, registered_phone, bank_name, bank_account, email} |
CreditGranted | Manager | Positive tops up, negative reclaims |
Days, DaysExplicit | Manager | Validity days of the added credit, see below |
Status | Manager (not for yourself) | false disables the account |
DailyLimit, HardLimit, SoftLimit | Manager | Daily and monthly credit; SoftLimit is only stored and not used for admission |
RPM, RPH, RPD, TPM, TPH, TPD | Manager | Account-level rate limits |
UserLimit | Manager | Sub-account quota |
Rates, Gear | Manager | Price multiplier (not below yours), routing mode (not above yours) |
ModelLimits | Manager | Model-level limits |
Resources, AllowIPs, AllowModels, AllowLevels | Manager | Allowlists, see below |
ModelMapper | Manager | Account-level model mapping |
Scope, DryRun | Manager | Narrow descendants' allowlists in bulk, see below |
When updating yourself, you may change only Email, Alias, BillingEmail, InvoiceInfo, and QRCode.
Credit adjustment
- Each update incurs one management call fee.
- A positive
CreditGrantedis transferred from your balance (converted byRates); a negative one returns credit to your balance, capped by the target's balance, and incurs one more management call fee. Daysis only a cap here: the expiry of the new credit is no later than the latest expiry of your own credit; withoutDays, the source credit's expiry is kept.- When
|CreditGranted| > 0.5, a credit-change email is sent to the target.
Allowlist syntax
The values of Resources, AllowIPs, AllowModels, and AllowLevels are strings whose items are separated by commas, semicolons, or whitespace:
| Form | Meaning |
|---|---|
a b c | Append these items (a bare list without prefix appends and never removes existing items) |
+x | Add one item |
-x | Remove one item |
* | Restore to your scope |
-* | Clear. The combination -*,+a,+b replaces the scope entirely with a and b |
AllowIPsaccepts single IPs and CIDR; loopback addresses are always allowed. AfterAllowLevelsis cleared, the account can still use its own Level.AllowModelssupports*wildcards, for examplegpt-6*.Resourcesmatches by path prefix, for example/v1/chat/completions,/v1/responses.- The scope you set is intersected with your own scope; invalid items are skipped.
Scope narrows a whole subtree at once: "Scope": "self" | "descendants" | "tree", supported for Resources and AllowModels only; combine it with "DryRun": true to preview the affected range first. This path reports invalid items as errors.
ModelLimits
{"ModelLimits": {"gpt-6.2-sol": {"rpm": 30, "tpm": 400000}}}- Keys must be the exact upstream model name (the mapped name); wildcards are not supported, and models absent from the pricing catalog are ignored.
- Inner keys are lowercase
rpm,rph,rpd,tpm,tph,tpd. Dimensions not given in a new entry are unlimited; when updating an existing entry, dimensions not given keep their value. - Limits apply only to accounts with
role2 (strict) and 3 (subscription); see Access Control and Limits.
Response (200): {"Action": "update", "User": {"ID": 42, "Updates": {...}}}, where Updates is the complete snapshot after the update. Every update writes an "Account Update" notice to the target, valid for 1 day.
Batch credit adjustment
curl -X POST "$BASE_URL/x-users/batch-credit" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"CreditGranted": 50, "Filters": {"level": 2}, "Order": "asc", "DryRun": true}'| Field | Description |
|---|---|
CreditGranted | Required, non-zero: positive grants, negative reclaims (priced as the sub-account) |
IDs | List of target IDs (at most 8192). [] matches no account |
Filters | id, name, email, dna (prefix), level, gear, role, tier, factor |
Order | desc sorts by ID descending, anything else ascending |
Days, DaysExplicit | Same as the update endpoint |
DryRun | true computes without writing |
- The target range is the intersection of all your descendants with
IDsandFilters. When neitherIDsnorFiltersis given, all descendants match (at most 8192; more returns400 Too many target users), so always preview withDryRunfirst. - Reclaims are executed in full only; accounts with insufficient balance are skipped.
- Once your balance runs short, all later grants are skipped, so the result depends on
Order. - The whole batch incurs a single management call fee.
Response:
{
"Action": "batch_credit", "DryRun": false, "CreditGranted": 50,
"RequestedCount": 3, "AppliedCount": 2, "SkippedCount": 1,
"TotalChildDelta": 100, "TotalParentDelta": -100.012,
"ParentBalanceBefore": 1000, "ParentBalanceAfter": 899.988, "ApiFee": 0.012,
"Results": [{"ID": 7, "Name": "dev-a", "Status": "applied", "CreditGranted": 50, "ParentDelta": -50, "Balance": 150}]
}Status values: applied, skipped_not_found, skipped_forbidden, skipped_parent_insufficient, skipped_invalid_rate, skipped_level_mismatch, skipped_parent_gear, skipped_child_insufficient, skipped_invalid_credit_state.
Delete an account
curl -X DELETE "$BASE_URL/x-users/dev-a" -H "Authorization: Bearer $API_KEY"- You can delete only your own descendants.
- Deletion is a hard delete and does not cascade: the deleted account's sub-accounts stay in the original subtree and remain manageable by ancestors above.
- The deleted account's positive balance is returned to your balance converted by
Rates, debt is deducted from your balance, and one management call fee is charged. If the target's daily token limit is not above 800000000, or the target's Level differs from yours, the positive balance is not returned. - A notification email is sent to the deleted account.
Response: {"Action": "delete", "User": {"ID": 42, "Name": "dev-a", "Email": "...", "Rates": 1, "CreditBalance": [...]}}.
Rotate your own key
curl -X POST "$BASE_URL/x-self" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d "{\"confirm\": \"$(date +%F)-ROTATE-SELF\"}"| Field | Description |
|---|---|
confirm | Required confirmation phrase: <current service date YYYY-MM-DD>-ROTATE-SELF |
key | Optional; specify the new 51-character sk-Xvs key; generated when omitted |
- The old key is invalidated immediately, and the new key is returned in the response and sent to your
EmailandBillingEmail. Prepare a safe update procedure first. - After a successful rotation you cannot rotate again for a while:
429 API Key was regenerated recently. Please try again later.(withRetry-After).
{"success": true, "message": "Self key rotated successfully",
"rotate": {"action": "rotate_self", "id": 42, "name": "dev-a", "email": "...", "key": "sk-Xvs...", "timestamp": "..."}}Notices
curl -X POST "$BASE_URL/x-news/dev-a" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"title": "Maintenance", "content": "Upstream switch tonight at 23:00.", "days": 3}'| Path | Target | Permission |
|---|---|---|
/x-news/{ID, account name, or email} | A specific account | The target must be your descendant |
/x-news/.{DNA} | Accounts whose DNA equals that value exactly (direct children of the same parent) | The DNA must contain your ID |
- Body:
title(optional),content(required),days(1 to 32; out-of-range values count as 32). - At most the 8 most recent notices are kept per target.
DELETEon the same path removes all notices of that target.- Accounts read them through
GET /dashboard/news; personal notices are cleared after being read once.