Official TypeScript/JavaScript SDK for the AgentRef REST API v1.
npm install agentrefimport { AgentRef } from 'agentref'
const client = new AgentRef({ apiKey: 'ak_live_...' })
const programs = await client.programs.list()
console.log(programs.meta.requestId)- API key is sent as
Authorization: Bearer <key>. - Supported key prefixes:
ak_live_*,ak_aff_*. - You can pass
apiKeydirectly or useAGENTREF_API_KEY. - Default behavior hard-fails in browser contexts to prevent API key exposure.
client.programslist,listAll,get,create,update,delete,stats,listAffiliates,listCoupons,createCoupon,deleteCoupon,listInvites,createInvite,updateMarketplace,connectStripe,disconnectStripe,verifyDomain,removeDomainVerification,getDomainStatus
client.affiliateslist,get,approve,block,unblock
client.conversionslist,stats,recent
client.payoutslist,listPending,stats,create
client.flagslist,stats,resolve
client.billingcurrent,tiers,subscribe
client.merchantget,update,getPayoutInfo,updatePayoutInfo,getNotifications,updateNotifications
client.webhookslist,create,get,update,delete,rotateSecret
List endpoints return:
{
data: T[]
meta: {
total: number
page: number
pageSize: number
hasMore: boolean
nextCursor?: string
requestId: string
}
}For auto-pagination use listAll(). Stop condition is meta.hasMore === false.
POST methods with server idempotency support accept options?: { idempotencyKey?: string }.
- If set,
Idempotency-Keyis sent. - Retries for mutating requests are only enabled for POST +
idempotencyKey. - PATCH/DELETE are never auto-retried.
import { AgentRef, ForbiddenError, NotFoundError, RateLimitError, AgentRefError } from 'agentref'
const client = new AgentRef({ apiKey: 'ak_live_...' })
try {
await client.programs.get('unknown')
} catch (error) {
if (error instanceof ForbiddenError) console.log(error.code)
if (error instanceof NotFoundError) console.log(error.requestId)
if (error instanceof RateLimitError) console.log(error.retryAfter)
if (error instanceof AgentRefError) console.log(error.status)
}| Option | Default | Description |
|---|---|---|
apiKey |
process.env.AGENTREF_API_KEY |
API key |
baseUrl |
https://www.agentref.dev/api/v1 |
Base API URL |
timeout |
30000 |
Request timeout in ms |
maxRetries |
2 |
Retry count for GET/HEAD and POST+idempotencyKey |
dangerouslyAllowBrowser |
false |
Allows browser initialization (unsafe) |