Skip to content

Getting Started

Getting Started with Bridge402

Welcome to Bridge402! This guide will help you get up and running with the Bridge402 API in minutes.

What is Bridge402?

Bridge402 is a crypto-native API service that bridges Web2 premium APIs to Web3 applications through x402 payments. It enables:

  • 🤖 AI Agents to access premium APIs programmatically
  • 🌐 Decentralized Apps to consume paid APIs with crypto payments
  • Real-time News Streams via WebSocket connections
  • 📊 Financial Data including earnings call transcripts
  • 💰 Pay-per-Use model with no subscriptions required

Quick Start

Prerequisites

  • A Web3 wallet (Ethereum/Solana compatible)
  • USDC on Base mainnet or Solana mainnet
  • API access via x402 payment protocol

Step 1: Choose Your Network

Bridge402 supports two blockchains:

  • Base (EVM): Use MetaMask or any EVM-compatible wallet
  • Solana: Use Phantom, Solflare, or any Solana wallet

Step 2: Install Dependencies

Python
pip install x402-python httpx websockets
JavaScript/Node.js
npm install @solana/web3.js @solana/spl-token ws undici

Step 3: Create Your First Session

Here's a minimal example to get started:

import httpx
from x402 import X402Client
from x402.schemes.exact import ExactScheme

# Initialize client
api_url = "https://bridge402.tech"
client = X402Client(private_key, network="base")

# Create a 5-minute session
async with httpx.AsyncClient() as http:
    # Get payment requirements
    response = await http.post(f"{api_url}/connect", params={"duration_min": 5})

    if response.status_code == 402:
        payment_req = response.json()["accepts"][0]

        # Generate payment
        payment = client.create_payment(
            scheme=ExactScheme(),
            amount=int(payment_req["maxAmountRequired"]),
            asset=payment_req["asset"],
            pay_to=payment_req["payTo"],
            resource=payment_req["resource"],
            description=payment_req["description"]
        )

        # Submit payment
        response = await http.post(
            f"{api_url}/connect",
            params={"duration_min": 5},
            headers={"X-PAYMENT": payment.encode()}
        )

        session = response.json()
        print(f"Session created! Token: {session['access_token']}")

Step 4: Connect to WebSocket Stream

import websockets
import json

async def stream_news(token):
    uri = f"wss://bridge402.tech/stream?token={token}"

    async with websockets.connect(uri) as ws:
        # Connection confirmation
        welcome = await ws.recv()
        print(json.loads(welcome))

        # Stream news messages
        async for message in ws:
            news = json.loads(message)
            if "title" in news:
                print(f"📰 {news['title']}")

Common Use Cases

🤖 AI Agent Integration

Enable autonomous AI agents to access premium APIs:

class AIAgent:
    async def get_crypto_news(self):
        session = await self.create_session(minutes=10)
        async for news in self.stream_news(session.token):
            yield news.content  # Feed to AI model

📱 Mobile App Integration

Use crypto payments instead of credit cards:

// React Native example
const purchaseAccess = async (minutes) => {
  const payment = await generatePayment(minutes);
  const response = await fetch(`${API_URL}/connect`, {
    method: 'POST',
    headers: { 'X-PAYMENT': payment },
    body: JSON.stringify({ duration_min: minutes })
  });
  return response.json();
};

🔄 Real-time Trading Bot

Monitor news for trading signals:

async def trading_bot():
    session = await create_session(minutes=60)

    async for news in stream_news(session.token):
        if analyze_sentiment(news) == "strong_buy":
            execute_trade(news.symbol)

Pricing

Bridge402 uses a transparent pay-per-use model:

  • News Stream: $0.0035 USDC per minute
  • Earnings Transcripts: $0.05 USDC per document
  • Minimum Purchase: 5 minutes ($0.0175 USDC)

Example Costs: - 10 minutes of news: $0.035 USDC - 1 hour of news: $0.21 USDC - 10 transcripts: $0.50 USDC

Next Steps

  1. 📖 Read the Payment Integration Guide for detailed payment flow
  2. 🔌 Explore WebSocket Streaming for real-time data
  3. 📊 Check out Examples for complete code samples
  4. 🛠️ Review the API Reference for all endpoints

Need Help?


Ready to build? Start with our example code and customize it for your needs!