FRAGMENT API REFERENCE

Public API reference

SDK 1.4.0 · Verified 12 October 2026 · Documentation

01 / OVERVIEW

What is Fragment API?

Fragment API is a backend API for buying Telegram Stars and gifting Telegram Premium through Fragment. Telegram bots, shops, marketplaces, and services can integrate it through the Python SDK or REST API, pay with GRAM or USDT on TON, and track delivery with one purchase ID.

The API turns Fragment's purchase flow into a small server-to-server interface: create a purchase, store the returned ID, poll the status, and finish only after a terminal result. No API key is required, and the public API does not add an API access fee.

Telegram Stars API

Buy from 50 to 1,000,000 Stars for a supported Telegram username.

Telegram Premium API

Gift 3, 6, or 12 months of Telegram Premium through the same purchase endpoint.

GRAM or USDT on TON

Choose gram or usdt. USDT purchases require a small GRAM balance for TON network fees.

Python SDK and REST

Use typed Python helpers or send ordinary JSON requests from any backend language.

02 / USE CASES

Who uses the Telegram Stars API?

The Telegram Stars API is designed for services that already manage an order and need a reliable backend purchase step. It fits Telegram bots, digital-goods shops, reseller panels, marketplaces, support tools, and automated Premium gifting systems.

BOT

Telegram bots

Turn a confirmed bot order into Stars or Premium and return a final delivery result to the user.

SHOP

Stars stores

Add Telegram Stars to an existing checkout while keeping wallet credentials on a trusted backend.

B2B

Reseller backends

Queue purchases behind your own order IDs and reconcile every attempt through idempotency and polling.

GIFT

Premium gifting

Offer fixed 3, 6, or 12-month Telegram Premium gifts through the same integration pattern.

03 / INTEGRATION

Python SDK or direct REST API?

Choose the Python SDK for the shortest typed integration. Choose direct REST when your backend uses Node.js, PHP, Go, Java, another language, or requires complete control over HTTP requests and persistence.

OptionBest forWhat you get
Python SDKPython bots and servicesTyped purchase, price, wallet resolver, and polling helpers.
REST APIAny backend languagePlain JSON over HTTPS with the same products, payment methods, and statuses.
PUBLIC REPOSITORYExamples, OpenAPI, SDK guidance, and AI integration skill
Explore fragment-api-dev on GitHub ↗

04 / AVAILABILITY

Check availability before accepting payment

POST/api/v1/availability/check

Check whether a Telegram recipient can receive the selected Stars or Premium purchase before you accept payment from your customer. This request does not create an invoice and does not need wallet credentials.

Availability is a point-in-time check, not a reservation or delivery guarantee. Check again whenever the product, username, amount, or payment method changes.

Python SDK · Stars availability
from fragment_api import FragmentAPI

api = FragmentAPI()
check = api.check_stars_availability(
    '@telegram_user', 50, 'gram',
)
print(check.available, check.message, check.action)
1Check

Send product, username, amount, and payment method.

2Accept payment

Continue only when the result is AVAILABLE.

3Create purchase

Submit the wallet-backed purchase with one idempotency key.

4Poll

Track the purchase ID until a terminal status.

Availability results

CodeClient action
AVAILABLEContinue to payment and purchase creation.
RECIPIENT_NOT_FOUNDCheck the Telegram username.
RECIPIENT_INELIGIBLEChoose another recipient or product.
PREMIUM_ALREADY_ACTIVEChoose another recipient or duration.
PAYMENT_METHOD_UNAVAILABLEChoose another supported payment method.
Known result

HTTP 200 returns available: true or a specific business rejection. Do not ask for payment when it is false.

Inconclusive check

HTTP 400 means fix the input, 429 means wait for retry_after, and 503 means keep payment disabled and try again later.

Python SDK 1.4.0 — use check_stars_availability() or check_premium_availability().

06 / PRICES

Show current prices first

Price endpoints need no API key, username, wallet seed, or payment method. Prices are informational and not reserved; Fragment creates a fresh invoice when a purchase starts.

GET/api/v1/prices

Returns the 50-Stars reference plus Premium prices for 3, 6, and 12 months.

GET/api/v1/prices/quote

Returns an exact quote for 50–1,000,000 Stars or 3, 6, or 12 months of Premium.

Python SDK · Stars price
from fragment_api import FragmentAPI

api = FragmentAPI()
quote = api.get_stars_price(100)
print(quote.prices.gram, quote.prices.usdt, quote.stale)
Exact values

gram and usdt are decimal strings. Keep them as strings until your payment layer converts units.

Last known value

When stale is true, the API returned the latest available quote while Fragment pricing was temporarily unavailable.

Python SDK 1.4.0 — use get_prices(), get_stars_price(amount), or get_premium_price(months).

07 / WALLETS

Select the wallet you actually fund

POST/api/v1/wallets/resolve

Resolve the exact account before creating a purchase. This is required when a 12-word seed can derive more than one wallet.

Wallet inputSelectionResolver result
Legacy 24-word seed or Base64 keyNoneUses the supplied wallet directly.
12-word seedaccount_indexSelects the V5R1 account at that index.
12-word seedwallet_addressFinds the matching derived wallet.
12-word seedwallet_address + account_indexVerifies that the address and index match.
12-word wallet selection

A 12-word seed alone is not enough. Send wallet_address or account_index.

Python SDK wallet resolver
from fragment_api import FragmentAPI

# pip install fragment-api-dev==1.4.0
# POST https://api-stars.duckdns.org/api/v1/wallets/resolve
# A 12-word seed alone is invalid; resolution requires wallet_address or account_index (0..100).
api = FragmentAPI()
wallet = api.resolve_wallet(
    seed='<12_WORD_BIP39_SEED>',
    wallet_address='<TON_WALLET_ADDRESS>',
)
print(wallet.account_index, wallet.wallet_version)
1Resolve once

Call the resolver with the seed and a wallet address or account index.

2Save the index

Use the returned account_index in later Stars or Premium requests.

3Reuse for purchases

Send that index for Stars or Premium purchases.

Python SDK 1.4.0 — use resolve_wallet() before a Stars or Premium purchase.

Wallet recovery

CodeClient action
WALLET_SELECTION_REQUIREDAdd wallet_address or account_index.
INVALID_BIP39_SEEDCheck all 12 words and their order.
INVALID_WALLET_ADDRESSSend a valid TON friendly or raw address.
INVALID_ACCOUNT_INDEXSend an integer from 0 to 100.
WALLET_ADDRESS_MISMATCHCorrect the address/index pair or resolve again.
WALLET_INDEX_NOT_FOUNDCall the resolver and reuse its returned account_index.

08 / REQUEST

Create purchase

POST/api/v1/purchases

The same endpoint handles Stars and Premium. The product decides how amount is interpreted.

FieldTypeRequirement
productstringstars or premium
usernamestringStarts with @; letters, numbers, and underscores
amountintegerStars: 50 to 1,000,000. Premium: 3, 6, or 12 months
payment_methodstringgram or usdt (USDT on TON)
seedstring12/24-word mnemonic or canonical Base64 32-byte key; trusted backend only
wallet_addressstringOptional TON address used to find or verify a 12-word wallet
account_indexintegerOptional account index from 0 to 100; selects V5R1 with a 12-word seed
idempotency_keystring1-128 printable ASCII characters; one logical order

Accepted response

{
  "purchase_id": "9ea17a5e-...",
  "status": "queued",
  "status_url": "/api/v1/purchases/9ea17a5e-..."
}

09 / STATUS

Track delivery

GET/api/v1/purchases/:purchase_id

Poll using the returned ID. Use a measured interval, keep the same purchase record, and persist the final result.

curl 'https://api-stars.duckdns.org/api/v1/purchases/<PURCHASE_ID>' \
  -H 'Accept: application/json'
queued

Accepted and waiting for processing.

preparing

Creating a live Fragment purchase.

sending

Signing and submitting the wallet transaction.

submitted

Transaction submitted to TON.

confirming

Waiting for delivery confirmation.

completed

Purchase delivered successfully. Stop polling.

failed

Purchase failed. Stop polling and inspect error.

reconciliation_required

Outcome is uncertain. Do not create an automatic replacement.

Completed response

{
  "purchase_id": "9ea17a5e-...",
  "status": "completed",
  "transaction_hash": "<TRANSACTION_HASH>"
}

10 / SAFETY

One key per logical order

Generate the idempotency key in your order system before calling the API. Reuse it when retrying the same order; create a new one only for a genuinely new order.

Retry safely

Timeout or 5xx? Check the original purchase first, then retry with the same key.

Avoid duplicates

Never generate a fresh key simply because the first response was uncertain.

Reconciliation required

Do not create an automatic replacement purchase. Review the original transaction outcome first.

11 / RECOVERY

Errors with a next action

HTTPMeaningClient action
400Invalid requestFix the field described in details, then submit a new request.
404Purchase not foundCheck the purchase_id and environment.
409Idempotency conflictReuse a key only for the exact same logical order.
429Rate limitedWait for Retry-After before retrying.
500Internal errorKeep the same idempotency key and check purchase status first.
503Temporarily unavailableRetry later with the same idempotency key.

Log purchase_id, idempotency_key, HTTP status, error code, and response details. Never log the wallet secret.

12 / AI ASSISTED

Integrate with Codex or Claude

The public GitHub repository includes a portable Fragment API integration skill for Codex and Claude. It gives a coding agent the current request fields, wallet rules, examples, status handling, idempotency requirements, and safe retry behavior.

What the skill covers

Telegram Stars, Telegram Premium, GRAM, USDT on TON, Python SDK, REST, wallet selection, polling, and errors.

What it protects

Backend-only wallet secrets, stable idempotency keys, terminal-status checks, and manual reconciliation when the outcome is uncertain.

# Codex
cp -R skills/fragment-api-integration "${CODEX_HOME:-$HOME/.codex}/skills/"

# Claude
cp -R skills/fragment-api-integration "$HOME/.claude/skills/"

Then ask your coding agent: Use $fragment-api-integration to add Telegram Stars purchases to this project.

Open the Codex and Claude integration skill on GitHub ↗

13 / SECURITY

The secret can spend funds

This API accepts a spend-capable wallet secret.

Call it only from a trusted backend. Keep the secret encrypted at rest, limit process access, redact it from logs and traces, and never expose it to browser JavaScript or client-side forms.

  • Use HTTPS and set strict request timeouts.
  • Persist purchase IDs before acknowledging the customer order.
  • Rotate credentials if a secret appears in logs or source control.
Open public health endpoint ↗

CLIENT-SIGNED

Keep signing in your own wallet

Create a checkout with a public payer address. Your wallet signs the returned transaction; this flow accepts no seed.

POST/api/v1/checkouts
GET/api/v1/checkouts/:checkout_id
POST/api/v1/checkouts/:checkout_id/submitted

Send product, username, amount, payment_method, payer_address, and idempotency_key to create. Persist checkout_id, approve only a payable transaction before validUntil, then submit the signed boc. Only completed confirms delivery.

Read the full signing and recovery guide. The Python SDK provides create_checkout, get_checkout, submit_checkout, and wait_checkout on both sync and async clients.

14 / RESOURCES

Public integration resources

Use the public repository as the source for runnable examples, the REST specification, Python SDK installation, wallet resolver guidance, and integration support. The production API endpoint remains separate from the documentation and source repository.

YOUR NEXT STEP

Add Stars to your bot.

Python, Node.js, another backend, or AI-assisted coding: start with an example that matches your stack.

Get integration examplesTalk to @tondotdev