Skip to main content
The agentref Python package provides both synchronous and asynchronous clients for the AgentRef REST API v1. It uses httpx under the hood and returns Pydantic models for core resources. Some flexible surfaces, including Marketing Resources and parts of the affiliate workspace, return dictionaries or lists of dictionaries because their response shape can vary by resource kind.

Installation

Quick Start

Async Usage

Configuration

Resource Namespaces

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

Programs

Applications

Affiliates

Affiliate Workspace

create_link uses destination_path and custom_slug. The current update API accepts name, target_url, and is_active; 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

Notifications

Payout Info

Onboarding, Tracking, Invites, and Marketplace

The REST SDK onboarding namespace currently covers merchant profile upsert by company_name 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] with typed data and metadata:
Some convenience list methods return plain lists because their REST endpoints return array data directly. Examples include client.affiliate_workspace.list_programs(), client.affiliate_workspace.list_links(), client.marketing_resources.list(), client.marketing_resources.list_for_affiliate(), client.webhooks.list(), and client.conversions.recent().

Auto-pagination

The list_all() generator handles pagination automatically:

Idempotency

POST mutation methods accept an idempotency_key keyword argument. When provided, the request is safe to retry — the server guarantees at-most-once execution.
The SDK automatically retries failed requests (up to max_retries) 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 raises typed exceptions for all API failures:
All exceptions inherit from AgentRefError and include code, status, and request_id attributes.

Sync vs Async

The Python SDK ships with both synchronous and asynchronous clients:
The async client supports async with for automatic connection cleanup. All async resource methods are identical to their sync counterparts but return coroutines.