Skip to main content

Introduction

The HTTPayer Python SDK provides a simple interface for accessing 402-protected APIs using either proxy mode (API key) or relay mode (private key).

Installation

pip install httpayer

Quick Start

Proxy Mode

from httpayer import HTTPayerClient

client = HTTPayerClient()  # Uses HTTPAYER_API_KEY from environment
response = client.request("GET", "https://api.example.com/protected")
print(response.json())

Relay Mode

import os
from httpayer import HTTPayerClient

client = HTTPayerClient(
    private_key=os.getenv("EVM_PRIVATE_KEY")
)
response = client.request("GET", "https://api.example.com/protected")
print(response.json())

Direct Mode

When privacy_mode=False, the SDK does not call the HTTPayer server, it attempts to call the target API directly. Ideal for when you don’t need cross-chain or privacy. If the target API returns payment instructions on the selected network, the SDK will pay them directly.
import os
from httpayer import HTTPayerClient

client = HTTPayerClient(
    private_key=os.getenv("EVM_PRIVATE_KEY"),
    privacy_mode=False
)
response = client.request("GET", "https://api.example.com/protected")
print(response.json())

Key Features

  • Multiple Access Patterns: Proxy (API key), Relay (private key + privacy/cross-chain), or Direct (private key, no relay, single-chain)
  • Auto-handles 402: Automatically processes payment flows
  • Cross-chain Support: Pay on one chain, access APIs on another
  • Privacy Mode: Route payments through HTTPayer relay
  • Simulation: Preview costs without executing payments

Next Steps