Documentation

Base URL: https://fragment-api.mboxcommunity.org · All responses use the envelope {"success": true, …} or {"success": false, "error": {"error_code": "…", "message": "…"}}.

Authentication

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.

Endpoints

EndpointPurpose
GET /healthAvailability check.
GET /api/v1/pricesCurrent Stars prices (TON).
GET /api/v1/commission/ratesCurrent fee rates.
POST /api/v1/sessionOpen a session (see above).
POST /api/v1/stars/buyCreate a Stars order → prepared payment.
POST /api/v1/premium/buyCreate a Premium order (3 / 6 / 12 months) → prepared payment.
POST /api/v1/premium/check-eligibilityCheck whether a recipient can receive Premium.
POST /api/v1/orders/{id}/submitSubmit your locally-signed transaction (base64 BoC).
GET /api/v1/orders/{id}One order's status.
GET /api/v1/ordersYour recent orders.

Create an order

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).

Sign & submit

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.

The verification checklist

Your SDK must refuse to sign unless all of these hold — any failure means the payment is treated as untrusted:

  1. The payment answers the exact order you requested (product, amount/months, currency).
  2. It spends from your wallet only, in exactly the legs the product needs.
  3. The Fragment leg goes only to a pinned Fragment address (pinned in the SDK release — never an address the server names at runtime).
  4. USDT legs go only to your own locally-computed USDT wallet.
  5. Fee legs go only to the pinned service fee wallet.
  6. The fee is within your configured cap.
  7. The total is within your per-order spend limits (setting limits is mandatory).
  8. The signed message expires within 120 seconds, and can only be re-signed with the same seqno.

Python SDK

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"]))

Fees

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.

Errors

CodeMeaning
INVALID_API_KEYUnknown or revoked API key.
UNAUTHORIZEDMissing or expired session token.
INVALID_FRAGMENT_COOKIESYour Fragment session is invalid or expired — log in to Fragment again.
VALIDATION_ERRORA required field is missing or invalid.
USER_NOT_FOUNDThe recipient username does not resolve.
ORDER_NOT_FOUNDNo such order for your account.
ORDER_NOT_PREPAREDThe order is not waiting for a signed transaction.
TRANSFER_AMBIGUOUSThe payment may already be on its way — check the order status; do not re-pay.
FRAGMENT_ERRORFragment rejected the request (details in the message).