Nabeghe API · REST API · v1

Partner APIAccount, API key, wallet, usage and reseller management — for any authenticated external system, not just Nabeghe API's own dashboard.

Base URL & authentication

All requests are server-to-server, over HTTPS, to:

https://nabegheapi.ir/partner/v1

Authenticate with a management key — a distinct key type from the ordinary /v1/chat/completions gateway key. A management key can create/manage accounts, keys, and wallet credit; a gateway key can only send chat completions. Neither works on the other's surface.

Authorization: Bearer sk-nabegheapi-…

Management keys are minted by Nabeghe API staff only, one per partner account — ask your Nabeghe API contact for one. A management key can mint ordinary gateway keys for its own account (see POST /api-keys below), but it can never mint another management key — so a leaked key can't grant itself more access.

Errors

Standard HTTP status codes. Every error body has the same shape:

{
  "detail": {
    "error": { "code": "topup_not_enabled", "message": "شارژ خودکار کیف‌پول برای این حساب هنوز فعال نشده…" }
  }
}
StatusMeaning
400bad_phone (invalid owner_phone on customer create) · cannot_revoke_self (a key revoking itself)
401missing_api_key / invalid_api_key / key_disabled / key_expired
403wrong_key_kind (a gateway key was used here — management keys only) · ip_not_allowed · account_disabled · topup_not_enabled
404Not found, or not yours — the customers/* endpoints require a reseller account and 404 (never 403) on anything not owned by your account, so existence of another partner's resource is never disclosed.
409ref_id_conflict — a wallet top-up's ref_id was already used for a different customer (reusing it for the same customer/amount is the idempotent-retry path above, not a conflict).
429daily_topup_cap_exceeded / monthly_topup_cap_exceeded

Self — your own account

Every management key can call these for the account it belongs to.

GET/account
Your account: id, name, type, status, external_ref, markup_bps, child_billing, credit_limit_rial, created_at.
GET/wallet
balance_rial, lifetime_topup_rial, lifetime_spend_rial.
GET/usage
Month-to-date requests / cost_rial / tokens.
GET/api-keys
List your gateway keys (masked).
POST/api-keys
Mint a new gateway key for your own account. Body: name, optional rpm_limit/tpm_limit/concurrency_limit/monthly_cap_rial. The secret is returned once — store it now.
POST/api-keys/{id}/revoke
Permanent. Rejects revoking the key you're currently authenticated with.

Reseller — customers (sub-accounts)

Requires your account to be a reseller (ask Nabeghe API staff to enable this) — every other management key gets a 404 here, not a 403, so the existence of this surface isn't disclosed either.

GET/customers
List your customers.
POST/customers
Create a customer. Idempotent via external_ref — your own id for them; retrying with the same value returns the existing customer, never a duplicate. Body: name (required), external_ref, note (staff-visible only), markup_bps (omit to inherit your own reseller markup), type (individual | business, default business), owner_phone — optional, links this customer to a phone so the same person can also sign in directly to the Nabeghe API customer dashboard.
GET/customers/{id}
One customer + its wallet + its keys.
PATCH/customers/{id}
Body: any of name, markup_bps, status (active | suspended) — only fields you send are changed. Send clear_markup: true to reset this customer back to inheriting your own reseller markup instead of setting a new markup_bps value.
GET/customers/{id}/usage
That customer's month-to-date usage.
GET/customers/{id}/api-keys
List that customer's gateway keys.
POST/customers/{id}/api-keys
Mint a gateway key for that customer — this is the key their own application uses to call /v1/chat/completions directly, billed to their own wallet.
POST/customers/{id}/api-keys/{kid}/revoke
Permanent.
GET/customers/{id}/wallet
That customer's balance.
POST/customers/{id}/wallet/topup
Credit that customer's wallet. See below — this one has real guardrails.

Wallet top-up — the fine print

Self-service top-up is off by default for every reseller. Nabeghe API staff must explicitly grant a rolling daily + monthly cap before this endpoint works at all — until then it returns 403 topup_not_enabled. This bounds worst-case exposure if a key ever leaks.

Always send a ref_id — your own idempotency key (e.g. your payment/order id). Retrying the exact same ref_id returns the original result and never double-credits, even under a race.

POST /partner/v1/customers/482/wallet/topup
Authorization: Bearer sk-nabegheapi-…
Content-Type: application/json

{
  "amount_rial": 500000,
  "ref_id": "order-91827",
  "note": "top-up after payment confirmation"
}
200 OK
{ "ok": true, "balance_rial": 1500000, "ledger_entry_id": 9134 }

A retried request with the same ref_id returns { "ok": true, "idempotent_hit": true, "balance_rial": …, "ledger_entry_id": … } instead of crediting again.

Quick start

curl https://nabegheapi.ir/partner/v1/account \
  -H "Authorization: Bearer sk-nabegheapi-…"