Getting Started

Seller API

Base URL: https://api.shopaikey.com/seller

Introduction

The Seller API is exclusively for ShopAIKey Sellers (Resellers). Through this API, sellers can automate credit management, create and distribute API keys to their end customers.

With the Seller API, you can:

  • Check your seller account credit balance.
  • Create new API keys (single or bulk) for customers and deduct the corresponding credit.
  • Choose a group (channel group) for a key when creating it, or change it later.
  • Top up, deduct, or delete keys to refund credit back to your seller account.
  • Manage key status and names.
  • Top up credit to your seller account via bank transfer.
  • View usage statistics and transaction history.
  • Integrate into your sales system, Telegram bot, or own website for 24/7 automated operation.

Note: This API is not for end users. Only accounts granted Seller permission can use the endpoints below.


Authentication

Every request requires your seller secret key in a header:

code
Authorization: Bearer sk-xxx

or:

code
x-secret-key: sk-xxx

Security warning: The seller secret key can operate directly on your credit balance. Never share it, never commit it to git, and never embed it in client-side code.


Units

FieldUnit
Seller credit, userCredit, refunded, amount_vnd, price_vnd, totalSpent, keySpentxu (1 xu = 1 ₫), the seller wallet balance
amount when creating/topping up/deducting a key, balance, keyBalance, used, remainingUSD credit of the key

When you create or top up a key, the seller wallet is charged the xu equivalent of the USD credit at seller pricing (seller discount applied). When you deduct from or delete a key, the unused credit is converted back to xu at the price actually paid for that key.


Quick Start

1. Check seller account info

code
curl -X GET https://api.shopaikey.com/seller \
  -H "Authorization: Bearer sk-your-seller-secret-key"

2. List available groups

code
curl -X GET https://api.shopaikey.com/seller/groups \
  -H "Authorization: Bearer sk-your-seller-secret-key"

3. Create a new API key for a customer

code
curl -X POST https://api.shopaikey.com/seller/keys \
  -H "Authorization: Bearer sk-your-seller-secret-key" \
  -H "Content-Type: application/json" \
  -d '{"amount": 10, "name": "Key for customer A"}'

4. List issued keys

code
curl -X GET "https://api.shopaikey.com/seller/keys?page=1&limit=20" \
  -H "Authorization: Bearer sk-your-seller-secret-key"

Endpoints

1. Get seller info

Endpoint: GET /seller

Description: Returns the seller account info: email, wallet balance (xu) and the seller discount currently applied.

Response:

code
{
  "id": 1,
  "email": "[email protected]",
  "credit": 1500000,
  "seller_discount": 0.2
}
FieldTypeDescription
creditnumberSeller wallet balance (xu)
seller_discountnumberSeller discount, e.g. 0.2 means 20% off

2. List groups

Endpoint: GET /seller/groups

Description: Returns the groups that can be assigned to keys, the default group and each group's price ratio. A model's credit price in a group = the model's base price × that group's ratio.

Response:

code
{
  "groups": {
    "default": "Default",
    "claude": "Claude"
  },
  "defaultGroups": {
    "cheap": "default"
  },
  "groupRatios": {
    "default": 1,
    "claude": 1.2
  }
}
FieldTypeDescription
groupsobjectAllowed groups: the key is the group name, the value its label
defaultGroupsobjectGroup assigned to a key when group is not sent
groupRatiosobjectPrice ratio by group name; only use groups listed in groups

3. List keys issued by the seller

Endpoint: GET /seller/keys

Query params:

ParamTypeDescription
searchstringSearch by key name or key value
statusstringFilter by status: active, inactive, expired
typestringFilter by type: cheap
pageintegerPage, starting at 1. Send page or limit to enable paging
limitintegerKeys per page (default 20, max 200)
statsstringSend 0 to skip the stats block for a faster response

Without page/limit, all keys are returned.

Response:

code
{
  "keys": [
    {
      "id": 1,
      "key": "sk-abc123...",
      "name": "Key for customer A",
      "type": "cheap",
      "balance": 50,
      "status": "active",
      "created_at": "2026-01-01T00:00:00.000Z",
      "refundable": true,
      "used": 10,
      "remaining": 40,
      "tokenName": "Key for customer A",
      "tokenGroup": "default"
    }
  ],
  "total": 1,
  "page": 1,
  "limit": 20,
  "stats": {
    "total": 1,
    "active": 1,
    "inactive": 0,
    "remaining": 40,
    "used": 10
  }
}
FieldTypeDescription
balancenumberTotal USD credit granted to the key
usednumberUSD credit used
remainingnumberUSD credit remaining
tokenGroupstringGroup currently assigned to the key
refundablebooleanWhen false, deducting or deleting the key returns no xu
statsobjectTotals over the whole filter (not just the current page)

4. Create a key

Endpoint: POST /seller/keys

Body:

FieldTypeRequiredDescription
amountnumberYesUSD credit granted to the key, minimum 10
namestringNoA label for the key
groupstringNoGroup for the key (from GET /seller/groups); empty uses the default

Response:

code
{
  "key": "sk-generated-key...",
  "balance": 10,
  "id": 1
}

5. Create multiple keys at once

Endpoint: POST /seller/keys/bulk-create

Body:

FieldTypeRequiredDescription
amountnumberYesUSD credit per key, minimum 10
quantityintegerYesNumber of keys, from 1 to 50
namestringNoLabel; when creating several keys, suffixes _1, _2... are added
groupstringNoGroup for all keys; empty uses the default

All keys are created in one go; if credit is insufficient, no key is created.

Response:

code
{
  "keys": [
    { "id": 11, "key": "sk-aaa..." },
    { "id": 12, "key": "sk-bbb..." }
  ],
  "totalCostVnd": 52000
}
FieldTypeDescription
totalCostVndnumberTotal xu charged to the seller wallet

6. Top up a key

Endpoint: POST /seller/keys/:key_id/topup

Body:

FieldTypeRequiredDescription
amountnumberYesUSD credit to add, minimum 10 (charged to the seller wallet)

Response:

code
{
  "balance": 30
}

7. Deduct credit from a key (reclaim)

Endpoint: POST /seller/keys/:key_id/deduct

Description: Removes unused USD credit from the key and converts it back to xu in the seller wallet. Not available for keys with refundable: false.

Body:

FieldTypeRequiredDescription
amountnumberYesUSD credit to reclaim, greater than 0

Response:

code
{
  "keyBalance": 40,
  "userCredit": 1526000
}
FieldTypeDescription
keyBalancenumberUSD credit left on the key
userCreditnumberSeller wallet balance after refund (xu)

8. Update key status

Endpoint: PUT /seller/keys/:key_id/status

Body:

FieldTypeRequiredDescription
statusstringYesactive or inactive

Keys in expired status cannot be changed.

Response:

code
{
  "success": true,
  "status": "inactive"
}

9. Rename a key

Endpoint: PUT /seller/keys/:key_id/name

Body:

FieldTypeRequiredDescription
tokenNamestringYesNew name of the key

Response:

code
{
  "success": true
}

10. Change a key's group

Endpoint: PUT /seller/keys/:key_id/group

Description: Moves the key to another group. Takes effect on the key's next requests and does not change its credit.

Body:

FieldTypeRequiredDescription
groupstringYesGroup name from GET /seller/groups; empty string "" uses the default

Response:

code
{
  "success": true
}

11. Delete a key and refund credit

Endpoint: DELETE /seller/keys/:key_id

Response:

code
{
  "refunded": 104000
}

refunded is the xu returned to the seller wallet (0 if the key has refundable: false or is fully used).

Note: Deleted keys cannot be restored. Customers using the key lose access immediately.


12. Delete multiple keys

Endpoint: DELETE /seller/keys/bulk

Body:

FieldTypeRequiredDescription
idsarray of integerYesIDs of keys to delete

Response:

code
{
  "deleted": 3,
  "refunded": 312000,
  "failures": [
    { "id": 9, "error": "Không tìm thấy key" }
  ]
}

refunded is the total xu returned to the seller wallet. Keys that fail are listed in failures; the others are still deleted.


13. Create a seller credit top-up order

Endpoint: POST /seller/topup

Description: Creates an order to top up the seller wallet via bank transfer. Minimum 500,000 ₫, in multiples of 1,000 ₫. Once the transfer is received, the seller wallet is credited with exactly the amount transferred (xu).

Body:

FieldTypeRequiredDescription
amount_vndintegerYesAmount in VND (minimum 500,000, multiple of 1,000)

Response:

code
{
  "order_id": 123,
  "transfer_content": "NP123",
  "amount": 385,
  "price_vnd": 1000000,
  "qrUrl": "https://...",
  "bank_info": {
    "bankId": "...",
    "bankName": "...",
    "accountNo": "...",
    "accountName": "..."
  }
}
FieldTypeDescription
transfer_contentstringTransfer note; must be entered exactly for the order to match
amountnumberEquivalent USD credit at seller pricing (for reference)
price_vndintegerAmount to transfer (VND)
qrUrlstringVietQR image to scan for the transfer

14. Get a top-up order

Endpoint: GET /seller/topup/:order_id

Response: Same as POST /seller/topup, plus a status field (draft: awaiting payment, completed: credited, cancelled: cancelled).


15. Top-up history

Endpoint: GET /seller/topup-history

Query params:

ParamTypeDescription
pageintegerPage (default: 1)
limitintegerRecords per page (default 20, max 200)
searchstringSearch by transfer note
statusstringFilter by status: draft, completed, cancelled

Response:

code
{
  "orders": [
    {
      "id": 123,
      "amount": 385,
      "price_vnd": 1000000,
      "transfer_content": "NP123",
      "status": "completed",
      "created_at": "2026-04-28T08:00:00.000Z",
      "completed_at": "2026-04-28T08:02:10.000Z"
    }
  ],
  "total": 1,
  "page": 1,
  "totalPages": 1
}

16. Cancel an order

Endpoint: PUT /seller/orders/:id

Description: Cancels a top-up order still awaiting payment (draft).

Body:

FieldTypeRequiredDescription
statusstringYesOnly cancelled is supported

Response: The order after cancellation.


17. Cancel multiple orders

Endpoint: PUT /seller/orders/bulk

Body:

FieldTypeRequiredDescription
idsarray of integerYesIDs of orders to cancel
statusstringYesOnly cancelled is supported

Only orders in draft are cancelled.

Response:

code
{
  "updated": 2
}

18. Usage statistics

Endpoint: GET /seller/stats

Query params:

ParamTypeDescription
modestringdaily or monthly (default: daily)
fromstringStart date (YYYY-MM-DD)
tostringEnd date (YYYY-MM-DD)

Response:

code
{
  "totalSpent": 5000000,
  "totalOrders": 10,
  "keySpent": 4200000,
  "refunded": 150000,
  "totalRequests": 12500,
  "totalTokenUsed": 3200000,
  "spending": [
    { "date": "2026-04-28", "total": 500000, "count": 1 }
  ],
  "topModels": [
    { "modelName": "claude-sonnet-4-5", "requests": 5000, "tokenUsed": 1200000 }
  ]
}
FieldTypeDescription
totalSpentnumberTotal topped up to the wallet in the period (xu)
totalOrdersintegerNumber of completed top-up orders
keySpentnumberTotal xu spent creating and topping up keys
refundednumberTotal xu returned when deducting or deleting keys
totalRequestsintegerTotal requests made by the keys
totalTokenUsedintegerTotal tokens used
spendingarrayTop-ups by day or month
topModelsarrayMost used models

19. Transaction history

Endpoint: GET /seller/transactions

Query params:

ParamTypeDescription
pageintegerPage (default: 1)
limitintegerRecords per page (default 20, max 50)
typestringFilter by transaction type (see below)
typeMeaning
depositWallet top-up
key_purchaseNew key created
key_topupCredit added to a key
key_deductCredit deducted from a key, returned to wallet
key_refundKey deleted, unused credit returned to wallet

Response:

code
{
  "transactions": [
    {
      "id": 501,
      "type": "key_purchase",
      "amount_vnd": -26000,
      "description": "Tạo key cheap $10",
      "key_id": 1,
      "order_id": null,
      "created_at": "2026-04-28T08:05:00.000Z"
    }
  ],
  "total": 1,
  "page": 1,
  "totalPages": 1
}

A negative amount_vnd is charged to the wallet, a positive one is credited (xu).


Error Responses

HTTP CodeDescription
400Invalid parameters, insufficient credit, key not refundable
401Missing or invalid secret key
403Account is not a seller, or has not accepted the latest terms
404Key / order not found
500Server error
code
{
  "error": "Không đủ credit"
}

Error messages are in Vietnamese.


Seller Workflow Example

Scenario: a seller sells a $50 key to a customer, then the customer buys $30 more.

code
# 1. Check seller credit
curl -X GET https://api.shopaikey.com/seller \
  -H "Authorization: Bearer sk-your-seller-secret-key"

# 2. Create a $50 key for the customer in group "default"
curl -X POST https://api.shopaikey.com/seller/keys \
  -H "Authorization: Bearer sk-your-seller-secret-key" \
  -H "Content-Type: application/json" \
  -d '{"amount": 50, "name": "Customer_JohnDoe", "group": "default"}'

# 3. Customer buys $30 more
curl -X POST https://api.shopaikey.com/seller/keys/1/topup \
  -H "Authorization: Bearer sk-your-seller-secret-key" \
  -H "Content-Type: application/json" \
  -d '{"amount": 30}'

# 4. Customer stops using it; delete the key to reclaim leftover credit
curl -X DELETE https://api.shopaikey.com/seller/keys/1 \
  -H "Authorization: Bearer sk-your-seller-secret-key"

Security Notes for Sellers

  • Do not share your secret key with customers or third parties.
  • Do not commit your secret key to a git repository.
  • Always use HTTPS in production.
  • Rotate your secret key periodically or immediately if you suspect a leak.
  • Use meaningful key names (e.g. customer_abc_2026_01) for easy reconciliation.
  • Log every transaction on your side to reconcile with ShopAIKey when needed.