Grant meter credits from the runtime SDK
Merged
ST
15d ago+434+434+012345678901234567890123456789-33-33-01234567890123456789
Stacked on #15420. Uses the credits endpoint from #15405 and first requires https://github.com/polarsource/polar/pull/15440 to be merged.
Adds grant to the runtime SDK actor, so a merchant can give a customer credits from their server without a purchase:
await polar.actor({ externalCustomerId: userId }).grant('tool_call', 50, {
idempotencyKey: `survey:${userId}`,
})
- The meter name is type-checked against the config.
rolloverdefaults to true. idempotencyKeymaps to the endpoint'sexternal_id, so retrying doesn't grant twice.- The balance updates asynchronously, like it does for tracked events so the next
balance()reportspristine: falseuntil the credit is applied. - Credits always go to the customer, even on an actor with a member.
The demo app shows: a free customer who runs out of tool calls can answer "What are you building?" to get 10 tool calls instead of upgrading. The code panel has a new Grant step.
| Screenshots |
|---|