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
Conversions
Payouts
Fraud Flags
Billing
Merchant
Notifications
Payout Info
Onboarding, Tracking, Invites, and Marketplace
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 aPaginatedResponse[T] with typed data and metadata:
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
Thelist_all() generator handles pagination automatically:
Idempotency
POST mutation methods accept anidempotency_key keyword argument. When provided, the request is safe to retry — the server guarantees at-most-once execution.
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
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:async with for automatic connection cleanup. All async resource methods are identical to their sync counterparts but return coroutines.