# Balances and grants

Source: https://docs.orbytelabs.com/sdk/credits

Read available credits and fund a customer's features.

## Read a balance [#read-a-balance]

```typescript title="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](/sdk/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](/sdk/events) to verify feature access.

## Grant credits [#grant-credits]

```typescript title="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](/sdk/checkout#top-ups). See
[grants and top-ups](/grants-and-topups) for access and expiry rules.