Skip to content

getBusinessAccountStarBalance

Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns StarAmount on success.

Parameters

business_connection_idStringRequired
Unique identifier of the business connection

Returns

On success, the StarAmount object is returned.

GramIO Usage

ts
// Get the Star balance of a managed business account
const 
balance
= await
bot
.
api
.
getBusinessAccountStarBalance
({
business_connection_id
: "bc_123",
});
console
.
log
(`Star balance: ${
balance
.
amount
} ⭐`);
// nanostar_amount holds fractional stars (0–999_999_999) if (
balance
.
nanostar_amount
) {
console
.
log
(`+ ${
balance
.
nanostar_amount
} nanostars`);
}
ts
// Guard: check if the account has enough Stars before a transfer
async function 
hasEnoughStars
(
connectionId
: string,
required
: number) {
const
balance
= await
bot
.
api
.
getBusinessAccountStarBalance
({
business_connection_id
:
connectionId
,
}); return
balance
.
amount
>=
required
;
} const
canAfford
= await
hasEnoughStars
("bc_123", 50);
console
.
log
(`Can afford 50 Stars: ${
canAfford
}`);
ts
// Log balance whenever a business connection is established
bot
.
on
("business_connection", async (
ctx
) => {
if (!
ctx
.
isEnabled
) return;
const
balance
= await
bot
.
api
.
getBusinessAccountStarBalance
({
business_connection_id
:
ctx
.
id
,
});
console
.
log
(
`Connected account ${
ctx
.
user
.
id
} has ${
balance
.
amount
} Stars`
); });

Errors

CodeErrorCause
400Bad Request: business connection not foundThe business_connection_id is invalid or the connection was revoked — re-verify with getBusinessConnection
400Bad Request: not enough rightsThe bot lacks the can_view_gifts_and_stars business bot right — check connection.rights before calling
429Too Many Requests: retry after NRate limit hit — check retry_after, use auto-retry plugin

TIP

Use GramIO's auto-retry plugin to handle 429 errors automatically.

Tips & Gotchas

  • Requires can_view_gifts_and_stars right. This is granted by the business account owner during setup — verify it from connection.rights?.can_view_gifts_and_stars before calling to avoid needless errors.
  • StarAmount has two parts. amount is the integer Star balance. nanostar_amount (0–999,999,999) represents fractional precision — usually 0 in practice, but handle it if you display totals mathematically.
  • The balance is a point-in-time snapshot. Re-fetch just before any Stars transfer operation rather than relying on a cached value — the balance can change between calls.
  • This endpoint is read-only. You can't add or deduct Stars through this method. To transfer Stars, use the appropriate transfer endpoint.

See Also