ar.io Logoar.io Documentation
ar.io SDKAdvanced

Circuit Breaker

The SDK ships an [opossum]-backed circuit breaker that wraps the RPC transport. When the primary endpoint starts failing (429 rate-limits, 5xx errors, network timeouts) the circuit opens and subsequent calls route transparently to a fallback RPC until the primary recovers.

import { ARIO, createCircuitBreakerRpc } from '@ar.io/sdk';

const rpc = createCircuitBreakerRpc({
  primaryUrl: 'https://my-premium-rpc.example.com',
  fallbackUrl: 'https://api.mainnet-beta.solana.com',
});

const ario = ARIO.init({ rpc });

Use defaultFallbackUrl() to auto-pick mainnet or devnet based on the primary URL:

import {
  createCircuitBreakerRpc,
  defaultFallbackUrl,
} from '@ar.io/sdk';

const primaryUrl = 'https://my-premium-rpc.example.com';
const rpc = createCircuitBreakerRpc({
  primaryUrl,
  fallbackUrl: defaultFallbackUrl(primaryUrl), // → mainnet public RPC
});

Tuning knobs (all optional):

OptionDefaultDescription
timeout10000ms before a single request is timed out (false to disable)
errorThresholdPercentage50error % at which to open the circuit
resetTimeout30000ms to wait before probing the primary again (half-open)
volumeThreshold5minimum requests in the rolling window before the circuit can trip

How is this guide?