@x402tools/client
v1.0.1
Published
Official Stakefy JavaScript/TypeScript client for usage-based billing
Maintainers
Readme
@stakefy/client
Official JavaScript/TypeScript SDK for Stakefy - Usage-based billing infrastructure.
Installation
npm install @stakefy/clientQuick Start
const { StakefyClient } = require('@stakefy/client');
const stakefy = new StakefyClient('sk_pro_xxxxx');
// Create an envelope
const envelope = await stakefy.createEnvelope({
name: 'API Calls - November',
timeWindow: 'MONTHLY',
capacity: 10000,
currency: 'USD',
ownerAccountId: 'org_123'
});
// Record usage
const result = await stakefy.recordUsage({
envelopeId: envelope.id,
amount: 5,
identity: '[email protected]',
identityType: 'EMAIL'
});
console.log(`Remaining: ${result.remaining}`);API Reference
new StakefyClient(apiKey, baseURL?)
Creates a new Stakefy client.
apiKey(string, required) - Your API key from the dashboardbaseURL(string, optional) - Custom API URL (defaults to production)
createEnvelope(data)
Create a new envelope for tracking usage.
await stakefy.createEnvelope({
name: string,
timeWindow: 'HOURLY' | 'DAILY' | 'WEEKLY' | 'MONTHLY',
capacity: number,
currency: string,
ownerAccountId: string
});getEnvelope(id)
Get envelope details.
const envelope = await stakefy.getEnvelope('envelope_id');recordUsage(data)
Record usage against an envelope.
await stakefy.recordUsage({
envelopeId: string,
amount: number,
identity: string,
identityType: string,
metadata?: object
});TypeScript Support
Full TypeScript support included:
import { StakefyClient } from '@stakefy/client';
const stakefy = new StakefyClient('sk_pro_xxxxx');
// Fully typed!Links
License
MIT
