Skip to main content
The agentref package is a lightweight, fully-typed Node.js client for the AgentRef REST API v1. It handles authentication, retries, pagination, idempotency, and structured error handling out of the box.

Installation

Quick Start

Configuration

Never expose API keys in client-side code. The SDK throws an error if initialized in a browser context unless you explicitly opt in with dangerouslyAllowBrowser: true.

Resource Namespaces

The client exposes the full REST API v1 surface through resource namespaces:

Programs

Applications

Affiliates

Affiliate Workspace

createLink uses destinationPath and customSlug. The current update API accepts name, targetUrl, and isActive; create a new link when you need a different destination path or custom slug.

Marketing Resources

REST/SDK Marketing Resources support social posts, social-post media, publish/unpublish/archive/notify actions, and download URLs. Collection creation, external-link creation, generic file upload sessions, and URL import are currently available through Merchant MCP, not through the REST SDK.

Conversions

Payouts

Fraud Flags

Billing

Merchant

Onboarding, Tracking, Invites, and Marketplace

The REST SDK onboarding namespace currently covers merchant profile upsert by companyName and onboarding completion. Merchant MCP has additional setup tools for get_onboarding_status, get_tracking_snippet, and active tracking verification.

Webhooks


Pagination

Paginated REST list methods return a PaginatedResponse<T>:
Some convenience list methods return plain arrays because their REST endpoints return array data directly. Examples include client.affiliateWorkspace.listPrograms(), client.affiliateWorkspace.listLinks(), client.marketingResources.list(), client.marketingResources.listForAffiliate(), client.webhooks.list(), and client.conversions.recent().

Page-based pagination

Auto-pagination

The listAll() generator handles pagination automatically:

Idempotency

All mutation methods (POST) accept an idempotencyKey option. When provided, the request is safe to retry — the server guarantees at-most-once execution.
The SDK automatically retries failed requests (up to maxRetries) for:
  • GET/HEAD requests — always safe to retry
  • POST requests with an idempotency key — server-side deduplication
  • 429 (rate limited) and 5xx (server error) responses
POST requests without an idempotency key are never retried.

Error Handling

The SDK throws typed errors for all API failures:
All errors extend AgentRefError and include code, status, message, and requestId properties.

TypeScript Types

All types are exported from the package: