> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useroutr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI and API credits

> Sell credit packs for your AI app or API and let developers top up with any token. Your app adds the credits when the payment settles.

![Users top up AI credits with LINK on Base, ETH on Arbitrum or USDC on Stellar.](https://mintcdn.com/thirtn/tEtIKPxuXx_PTNHq/images/illustrations/use-case-ai-credits-light.svg?fit=max\&auto=format\&n=tEtIKPxuXx_PTNHq\&q=85\&s=c998653a3662fd2cbd99f18046d77ee6)

Hosted checkoutFunding intentsLedger

## The idea

Your model is brilliant, your API is fast, and your users' money is in five tokens on three
networks. Sell credits in USDC and let anyone top up with what they hold. Ten thousand credits are
one click away, whichever coin is in the wallet.

## How it plays out

**1. They pick a pack**

"10,000 credits for 10 USDC." Your server creates a funding intent and tags it with the user
and the pack.

**2. They pay**

Send them to the [hosted checkout](https://docs.useroutr.com/payments/hosted-checkout.md). It works from a dashboard, a
CLI that prints a link, or an email.

**3. Credits appear**

On `funding.credited`, add the credits to the user's balance in your app.

## The code

```ts Sell a pack theme={null}
const intent = await useroutr.fundingIntents.create(
  {
    amount: "10",
    asset: "asset_usdc_stellar",
    reference: purchaseId,
    metadata: { user_id: user.id, credits: 10_000 },
  },
  { idempotencyKey: purchaseId },
);

console.log(`Top up here: ${intent.hosted_funding_url}`);
```

```ts Add the credits theme={null}
// Inside your webhook handler, after verifying the event
if (event.type === "funding.credited") {
  const purchase = event.data.object;
  await addCredits({
    userId: String(purchase.metadata.user_id),
    credits: Number(purchase.metadata.credits),
    purchaseId: purchase.reference, // add each purchase once: deliveries can repeat
  });
}
```

```ts Check the books theme={null}
// A nightly job: every credited purchase should have its credits
for await (const purchase of useroutr.fundingIntents.iterate({ status: "CREDITED" })) {
  await ensureCreditsGranted(purchase.reference);
}
```

## Make it your own

* **Low-balance nudges.** When credits run low, email a link to a fresh top-up.
* **Team wallets.** Put a `team_id` in `metadata` and credit the team instead of a person.
* **A CLI top-up.** Print `hosted_funding_url` in the terminal; the payer opens it on any device.

## Good to know

* Crypto can't be pulled from a wallet without its owner, so there is no automatic top-up: each
  purchase is a payment your user makes.
* Price packs in a stable asset, so 10,000 credits cost the same tomorrow.
* The nightly check is cheap insurance: it catches a handler that was down when the webhook
  came, even after every retry.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.