Skip to Content
Orbyte Labs

Balances and grants

Read available credits and fund a customer's features.

Read a balance

TypeScript
import { balance } from "orbytelabs";

const result = await balance("customer_123");
console.log(result.availableCredits); // bigint, in ledger units

The shortcut reads ORBYTE_API_KEY. With an explicit client, use client.balances.get({ identity }). The result also includes asOf and an optional nextChangeAt timestamp.

The overall balance can differ from the amount available to one feature. Use check to verify feature access.

Grant credits

TypeScript
import { Orbyte, credits } from "orbytelabs";

const client = new Orbyte({ accessToken: process.env.ORBYTE_API_KEY });
const grantId = await client.grants.create({
  identity: "customer_123",
  credits: credits(5),
  idempotencyKey: "welcome_customer_123",
});

This grants five credits without collecting payment. The credits can fund any deployed feature by default, including features added later. Add featureKeys: ["requests"] to limit access to requests. Set expiresAt to a Unix millisecond timestamp to expire the grant. Retrying with the same key and unchanged input returns the same grant.

For paid credits, use top-up checkout. See grants and top-ups for access and expiry rules.

On this page