Base URL: https://fragment-api.mboxcommunity.org · All responses use the envelope {"success": true, …} or {"success": false, "error": {"error_code": "…", "message": "…"}}.
Purchases run under your Fragment account (KYC mode). You receive an API key (mfrag_…) when your account is approved. With it you open a session: your Fragment cookies (stel_ssid, stel_dt, stel_token) plus your TON account object (derived locally by the SDK — public parts only). Cookies are held in server memory only and never written to disk. No endpoint accepts a wallet seed.
POST /api/v1/session
{"api_key": "mfrag_…", "cookies": {"stel_ssid": "…", "stel_dt": "…", "stel_token": "…"},
"account": {"address": "0:…", "chain": "-239", "walletStateInit": "…", "publicKey": "…"}}
→ {"success": true, "session_token": "…", "customer_id": "…"}
Send the session token as Authorization: Bearer <session_token> on every other call. Sessions last 24 hours.
| Endpoint | Purpose |
|---|---|
GET /health | Availability check. |
GET /api/v1/prices | Current Stars prices (TON). |
GET /api/v1/commission/rates | Current fee rates. |
POST /api/v1/session | Open a session (see above). |
POST /api/v1/stars/buy | Create a Stars order → prepared payment. |
POST /api/v1/premium/buy | Create a Premium order (3 / 6 / 12 months) → prepared payment. |
POST /api/v1/premium/check-eligibility | Check whether a recipient can receive Premium. |
POST /api/v1/orders/{id}/submit | Submit your locally-signed transaction (base64 BoC). |
GET /api/v1/orders/{id} | One order's status. |
GET /api/v1/orders | Your recent orders. |
POST /api/v1/stars/buy Authorization: Bearer <session_token>
{"username": "@durov", "amount": 100, "currency": "TON",
"idempotency_key": "your-unique-key"}
→ {"success": true,
"order": {"id": "ord_…", "status": "prepared", …},
"payment": {"valid_until": 1730000000, "network": "-239",
"from": "<your wallet>",
"messages": [{"address": "…", "amount": "…", "payload": "…", "role": "fragment"},
{"address": "…", "amount": "…", "role": "fee"}]}}
Premium is the same shape with "months": 3 | 6 | 12 instead of amount. Stars: minimum 50, maximum 10,000,000 per order. Currencies: TON and USDT (USDT on TON).
Verify the prepared payment (checklist below), sign it locally, then submit the signed transaction cell:
POST /api/v1/orders/ord_…/submit
{"boc": "<base64 signed transaction>"}
→ {"success": true, "order": {"id": "ord_…", "status": "success", …}}
Order statuses: created → prepared → submitted → processing → success | failed. If a submission's outcome is ever uncertain, the order is marked ambiguous — reconcile it with GET /api/v1/orders/{id}; never pay twice. Repeating a buy with the same idempotency_key returns the original order instead of creating a new one.
Your SDK must refuse to sign unless all of these hold — any failure means the payment is treated as untrusted:
Source: github.com/mboxcommunity/fragment-api (sdk/). Requires Python 3.10+ and Node 18+ (for the bundled TON signing helper).
from fragment_api_sdk import FragmentAPI
api = FragmentAPI(api_key="mfrag_…",
cookies={"stel_ssid": "…", "stel_dt": "…", "stel_token": "…"},
seed="<24 words — never leaves this machine>",
max_ton_per_order=5_000_000_000) # mandatory
order = api.buy_stars("@durov", 100) # verify → sign locally → submit
order = api.buy_premium("@durov", 12)
print(api.get_order(order["id"]))
The service fee is 0.01% of the Fragment price. For TON orders it travels as its own leg inside your signed transaction, so every fee is verifiable on-chain. For USDT orders the fee is recorded in the order ledger and settled periodically. Your SDK enforces your own fee cap independently — a payment whose fee exceeds your cap is never signed.
| Code | Meaning |
|---|---|
INVALID_API_KEY | Unknown or revoked API key. |
UNAUTHORIZED | Missing or expired session token. |
INVALID_FRAGMENT_COOKIES | Your Fragment session is invalid or expired — log in to Fragment again. |
VALIDATION_ERROR | A required field is missing or invalid. |
USER_NOT_FOUND | The recipient username does not resolve. |
ORDER_NOT_FOUND | No such order for your account. |
ORDER_NOT_PREPARED | The order is not waiting for a signed transaction. |
TRANSFER_AMBIGUOUS | The payment may already be on its way — check the order status; do not re-pay. |
FRAGMENT_ERROR | Fragment rejected the request (details in the message). |