Skip to main content
Initialize HTTPayer client with automatic mode detection. Mode is auto-detected based on credentials:
  • “relay” mode: When private_key or account is provided (self-custodial)
  • “proxy” mode: When only api_key is provided (custodial)

Signature

HTTPayerClient(router_url: Optional = None, api_key: Optional = None, private_key: Optional = None, account: Optional = None, network: Optional = None, timeout: int = 600, use_session: bool = True, strict_networks: bool = True, response_mode: str = 'text', privacy_mode: bool = True)

Parameters

  • router_url: HTTPayer router URL. Defaults to https://api.httpayer.com or X402_ROUTER_URL env var.
  • api_key: API key for proxy mode. Defaults to HTTPAYER_API_KEY env var.
  • private_key: Private key for relay mode. Supports EVM (hex), Solana (base58/hex/JSON array).
  • account: Pre-configured EVM Account object for relay mode.
  • network: Default network for relay payments (e.g., “base”, “solana-mainnet-beta”).
  • timeout: Request timeout in seconds. Defaults to 600 (10 minutes).
  • use_session: Use requests.Session for connection pooling. Defaults to True.
  • strict_networks: Raise error for unsupported networks. Defaults to True.
  • response_mode: Response format - “text” (unwrapped) or “json” (wrapped). Defaults to “text”.
  • privacy_mode: Route through HTTPayer relay for privacy. When False, attempts direct x402 payment. Defaults to True.

Raises

  • ValueError: If response_mode is invalid, private_key format is invalid, or network is incompatible with wallet type.
  • ValueError: If proxy mode is detected but HTTPAYER_API_KEY is missing.

Examples

>>> # Proxy mode (API key)
>>> client = HTTPayerClient(api_key="your-api-key")
>>> # Relay mode (EVM private key)
>>> client = HTTPayerClient(private_key="0x...", network="base")
>>> # Relay mode (Solana private key)
>>> client = HTTPayerClient(private_key="base58-key", network="solana-mainnet-beta")