Package Exports
- @railslab/sdk
Readme
@railslab/sdk
Agent spend control SDK. Pay for API resources through Rails Lab.
Install
npm install @railslab/sdkUsage
import { Leet } from '@railslab/sdk'
const leet = new Leet({ apiKey: 'leet_abc123...' })
// Pay for a resource — protocol is auto-detected
const { content } = await leet.pay('https://pro-api.coingecko.com/api/v3/x402/simple/price?vs_currencies=usd&ids=bitcoin')
console.log(content) // { bitcoin: { usd: 70925 } }Options
const result = await leet.pay('https://api.example.com/resource', {
amountCents: 1, // Budget debit amount (default: 1 cent)
protocol: 'x402', // Skip auto-detection
method: 'POST', // HTTP method for the destination
body: '{"key": "val"}', // JSON body for POST destinations
idempotencyKey: 'abc', // For safe retries
metadata: { env: 'prod' },
})Error handling
import { Leet, LeetError } from '@railslab/sdk'
try {
await leet.pay('https://api.example.com/resource')
} catch (err) {
if (err instanceof LeetError) {
console.log(err.code) // "POLICY_DENIED", "BUDGET_EXCEEDED", etc.
console.log(err.message) // Human-readable message
console.log(err.status) // HTTP status code
}
}Supported protocols
| Protocol | Description |
|---|---|
| x402 | USDC payments on Base via Coinbase x402 |
| mpp-crypto | Tempo stablecoin payments via MPP |
| mpp-spt | Stripe card payments via MPP (coming soon) |
Protocol is auto-detected from the destination's 402 response. You can also specify it explicitly via the protocol option.