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 account

Endpoints

Method and pathPermissionDescription
POST /x-usersManager with remaining sub-account quotaCreate a direct sub-account
GET /x-users, GET /x-users/{identifier}ManagerQuery direct sub-accounts
GET /x-dna, GET /x-dna/{identifier}ManagerQuery all descendant accounts
PUT /x-users/{identifier} (or POST)Manager; the account itself may update some profile fieldsUpdate an account
POST /x-users/batch-creditManagerGrant or reclaim credit in batches
DELETE /x-users/{identifier}ManagerDelete a descendant account
POST /x-selfAny accountRotate your own API Key
POST /x-news/{target}, DELETE /x-news/{target}ManagerPublish 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
  }'
FieldRequiredDescription
EmailYesLogin and notification email, globally unique, at most 128 bytes
NameNoAccount name, globally unique; 2 to 63 bytes of letters, digits, _, and -, with at least one letter. Generated when omitted
AliasNoDisplay name, same rules as Name; derived from the email when invalid
BillingEmailNoBilling email; several allowed (separated by ,, ;, or whitespace, total length at most 256); defaults to Email
CreditGrantedNoInitial 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
RatesNoPrice multiplier, max(requested value, your Rates)
RPM, RPH, RPD, TPM, TPH, TPDNoAccount-level rate limits, each min(requested value, your value); inherit your value when omitted or below 1
UserLimitNoNumber of sub-accounts this sub-account may create; default 0. Forced to 0 when your own UserLimit is below 64
SecretKeyNoSpecify 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.

StatusBodyReason
400Invalid email addressInvalid email
400Name: 4-63 chars, at least 1 lettersInvalid account name (the actual lower bound is 2 bytes)
403Sub-user limit reached / Management access requires remaining sub-user quota.Sub-account quota exhausted
403Insufficient balanceNot enough balance to transfer
409User already existsThe 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 descendants

Query parameters (for /x-users and /x-dna themselves only):

ParameterDescription
id, name, email, levelExact match
dnaDNA prefix match
page, sizePagination; at most 8192 per page
orderdesc (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

FieldWho can set itDescription
Email, Alias, BillingEmail, QRCodeManager; the account itselfProfile
InvoiceInfoThe account itself onlyInvoice details {type, company_name, tax_no, registered_address, registered_phone, bank_name, bank_account, email}
CreditGrantedManagerPositive tops up, negative reclaims
Days, DaysExplicitManagerValidity days of the added credit, see below
StatusManager (not for yourself)false disables the account
DailyLimit, HardLimit, SoftLimitManagerDaily and monthly credit; SoftLimit is only stored and not used for admission
RPM, RPH, RPD, TPM, TPH, TPDManagerAccount-level rate limits
UserLimitManagerSub-account quota
Rates, GearManagerPrice multiplier (not below yours), routing mode (not above yours)
ModelLimitsManagerModel-level limits
Resources, AllowIPs, AllowModels, AllowLevelsManagerAllowlists, see below
ModelMapperManagerAccount-level model mapping
Scope, DryRunManagerNarrow 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 CreditGranted is transferred from your balance (converted by Rates); a negative one returns credit to your balance, capped by the target's balance, and incurs one more management call fee.
  • Days is only a cap here: the expiry of the new credit is no later than the latest expiry of your own credit; without Days, the source credit's expiry is kept.
  • When |CreditGranted| > 0.5, a credit-change email is sent to the target.
Updates realign the plan: any regular update of a descendant, even one that changes only profile data, aligns the target's Level, Role, model mapping, Level mapping, and support QR code with your own values; if the target's Level differs from yours, the target's positive balance is cleared first, and reclaiming across Levels is rejected. Check the target's plan settings first to avoid mistakes.

Allowlist syntax

The values of Resources, AllowIPs, AllowModels, and AllowLevels are strings whose items are separated by commas, semicolons, or whitespace:

FormMeaning
a b cAppend these items (a bare list without prefix appends and never removes existing items)
+xAdd one item
-xRemove one item
*Restore to your scope
-*Clear. The combination -*,+a,+b replaces the scope entirely with a and b
  • AllowIPs accepts single IPs and CIDR; loopback addresses are always allowed. After AllowLevels is cleared, the account can still use its own Level.
  • AllowModels supports * wildcards, for example gpt-6*.
  • Resources matches 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 role 2 (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}'
FieldDescription
CreditGrantedRequired, non-zero: positive grants, negative reclaims (priced as the sub-account)
IDsList of target IDs (at most 8192). [] matches no account
Filtersid, name, email, dna (prefix), level, gear, role, tier, factor
Orderdesc sorts by ID descending, anything else ascending
Days, DaysExplicitSame as the update endpoint
DryRuntrue computes without writing
  • The target range is the intersection of all your descendants with IDs and Filters. When neither IDs nor Filters is given, all descendants match (at most 8192; more returns 400 Too many target users), so always preview with DryRun first.
  • 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\"}"
FieldDescription
confirmRequired confirmation phrase: <current service date YYYY-MM-DD>-ROTATE-SELF
keyOptional; 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 Email and BillingEmail. 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. (with Retry-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}'
PathTargetPermission
/x-news/{ID, account name, or email}A specific accountThe 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.
  • DELETE on the same path removes all notices of that target.
  • Accounts read them through GET /dashboard/news; personal notices are cleared after being read once.