Buy from 50 to 1,000,000 Stars for a supported Telegram username.
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.
Gift 3, 6, or 12 months of Telegram Premium through the same purchase endpoint.
Choose gram or usdt. USDT purchases require a small GRAM balance for TON network fees.
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.
Telegram bots
Turn a confirmed bot order into Stars or Premium and return a final delivery result to the user.
Stars stores
Add Telegram Stars to an existing checkout while keeping wallet credentials on a trusted backend.
Reseller backends
Queue purchases behind your own order IDs and reconcile every attempt through idempotency and polling.
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.
| Option | Best for | What you get |
|---|---|---|
| Python SDK | Python bots and services | Typed purchase, price, wallet resolver, and polling helpers. |
| REST API | Any backend language | Plain JSON over HTTPS with the same products, payment methods, and statuses. |
04 / AVAILABILITY
Check availability before accepting payment
/api/v1/availability/checkCheck 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.
from fragment_api import FragmentAPI
api = FragmentAPI()
check = api.check_stars_availability(
'@telegram_user', 50, 'gram',
)
print(check.available, check.message, check.action)Send product, username, amount, and payment method.
Continue only when the result is AVAILABLE.
Submit the wallet-backed purchase with one idempotency key.
Track the purchase ID until a terminal status.
Availability results
| Code | Client action |
|---|---|
AVAILABLE | Continue to payment and purchase creation. |
RECIPIENT_NOT_FOUND | Check the Telegram username. |
RECIPIENT_INELIGIBLE | Choose another recipient or product. |
PREMIUM_ALREADY_ACTIVE | Choose another recipient or duration. |
PAYMENT_METHOD_UNAVAILABLE | Choose another supported payment method. |
HTTP 200 returns available: true or a specific business rejection. Do not ask for payment when it is false.
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.
/api/v1/pricesReturns the 50-Stars reference plus Premium prices for 3, 6, and 12 months.
/api/v1/prices/quoteReturns an exact quote for 50–1,000,000 Stars or 3, 6, or 12 months of Premium.
from fragment_api import FragmentAPI
api = FragmentAPI()
quote = api.get_stars_price(100)
print(quote.prices.gram, quote.prices.usdt, quote.stale)gram and usdt are decimal strings. Keep them as strings until your payment layer converts units.
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
/api/v1/wallets/resolveResolve the exact account before creating a purchase. This is required when a 12-word seed can derive more than one wallet.
| Wallet input | Selection | Resolver result |
|---|---|---|
| Legacy 24-word seed or Base64 key | None | Uses the supplied wallet directly. |
| 12-word seed | account_index | Selects the V5R1 account at that index. |
| 12-word seed | wallet_address | Finds the matching derived wallet. |
| 12-word seed | wallet_address + account_index | Verifies that the address and index match. |
A 12-word seed alone is not enough. Send wallet_address or account_index.
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)Call the resolver with the seed and a wallet address or account index.
Use the returned account_index in later Stars or Premium requests.
Send that index for Stars or Premium purchases.
Python SDK 1.4.0 — use resolve_wallet() before a Stars or Premium purchase.
Wallet recovery
| Code | Client action |
|---|---|
WALLET_SELECTION_REQUIRED | Add wallet_address or account_index. |
INVALID_BIP39_SEED | Check all 12 words and their order. |
INVALID_WALLET_ADDRESS | Send a valid TON friendly or raw address. |
INVALID_ACCOUNT_INDEX | Send an integer from 0 to 100. |
WALLET_ADDRESS_MISMATCH | Correct the address/index pair or resolve again. |
WALLET_INDEX_NOT_FOUND | Call the resolver and reuse its returned account_index. |
08 / REQUEST
Create purchase
/api/v1/purchasesThe same endpoint handles Stars and Premium. The product decides how amount is interpreted.
| Field | Type | Requirement |
|---|---|---|
product | string | stars or premium |
username | string | Starts with @; letters, numbers, and underscores |
amount | integer | Stars: 50 to 1,000,000. Premium: 3, 6, or 12 months |
payment_method | string | gram or usdt (USDT on TON) |
seed | string | 12/24-word mnemonic or canonical Base64 32-byte key; trusted backend only |
wallet_address | string | Optional TON address used to find or verify a 12-word wallet |
account_index | integer | Optional account index from 0 to 100; selects V5R1 with a 12-word seed |
idempotency_key | string | 1-128 printable ASCII characters; one logical order |
Accepted response
{
"purchase_id": "9ea17a5e-...",
"status": "queued",
"status_url": "/api/v1/purchases/9ea17a5e-..."
}09 / STATUS
Track delivery
/api/v1/purchases/:purchase_idPoll 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'queuedAccepted and waiting for processing.
preparingCreating a live Fragment purchase.
sendingSigning and submitting the wallet transaction.
submittedTransaction submitted to TON.
confirmingWaiting for delivery confirmation.
completedPurchase delivered successfully. Stop polling.
failedPurchase failed. Stop polling and inspect error.
reconciliation_requiredOutcome 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.
Timeout or 5xx? Check the original purchase first, then retry with the same key.
Never generate a fresh key simply because the first response was uncertain.
Do not create an automatic replacement purchase. Review the original transaction outcome first.
11 / RECOVERY
Errors with a next action
| HTTP | Meaning | Client action |
|---|---|---|
400 | Invalid request | Fix the field described in details, then submit a new request. |
404 | Purchase not found | Check the purchase_id and environment. |
409 | Idempotency conflict | Reuse a key only for the exact same logical order. |
429 | Rate limited | Wait for Retry-After before retrying. |
500 | Internal error | Keep the same idempotency key and check purchase status first. |
503 | Temporarily unavailable | Retry 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.
Telegram Stars, Telegram Premium, GRAM, USDT on TON, Python SDK, REST, wallet selection, polling, and errors.
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.
13 / SECURITY
The secret can spend funds
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.
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.
/api/v1/checkouts/api/v1/checkouts/:checkout_id/api/v1/checkouts/:checkout_id/submittedSend 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.
Public README, releases, integration files, and project history.
↗EXAMPLESReady-to-run examplesStars and Premium with GRAM or USDT using Python, Node.js, and curl.
↗REFERENCEOpenAPI specificationMachine-readable public routes, fields, statuses, and errors.
↗PYTHONfragment-api-dev on PyPIInstall the public Python SDK version 1.4.0.
↗AI AGENTSCodex and Claude skillPortable integration instructions for coding agents.
↗SUPPORTIntegration issuesAsk for public integration help without posting wallet credentials.
↗