Developer Guide

How PayGate Works, From Zero to First Call

No blockchain experience required. This guide walks you through every concept — from the problem with API keys to your first micropayment settling on Stellar.

~10 min readBeginner-friendlyNo setup required
01The Problem

Why API Keys & Subscriptions Are Broken

Before we understand PayGate, we need to understand the problem it solves. Imagine you're building an app that needs weather data. Here's what the old world looks like:

🌐

You find a Weather API you want

Great! They charge $0.001 per call

📝

Sign up, verify your email, fill a form

Just to try it once

💳

Enter your credit card

They require a $10/month minimum

🔑

Get an API key — store it securely

Hope it never leaks or expires

📊

Track usage manually

Hope you don't exceed your plan

😩

Do this 20x for 20 different APIs

For every service your app needs

The real problem for AI Agents: An AI agent browsing the web autonomously cannot sign up for 15 different subscriptions, manage 15 API keys, or enter a credit card number. The existing model is fundamentally incompatible with the agentic internet.
02The Protocol

x402 — The HTTP Status Code That Was Forgotten

Here's something wild: the HTTP specification has had a 402 Payment Required status code since 1999. It was designed for exactly this use case — paying for internet resources on-demand. But it was never used because there was no internet-native money yet.

How x402 Works — Request/Response Flow

1.

Client → GET /api/x/weather-london

Normal request, no payment yet

2.

Server → 402 Payment Required

X-Payment-Required: {"amount":"0.001", "currency":"USDC", "dest":"G...wallet"}

3.

Client signs a Stellar micropayment

Wallet creates a transaction for exactly $0.001 USDC

4.

Client → GET /api/x/weather-london

X-Payment: {"signature":"abc123..."}

5.

Server → 200 OK + weather data

Payment verified, request proxied, developer earns USDC

Think of it like a vending machine: Instead of a monthly subscription, you pay a coin per item. The machine verifies your coin and gives you exactly what you asked for. x402 is the protocol that standardizes this for any HTTP API.
03The Blockchain

Why Stellar? Why USDC?

For API micropayments to work, the money layer needs to be fast, cheap, and stable. Here's why PayGate chose Stellar and USDC specifically:

~5 second finality

Stellar settles transactions in under 5 seconds. Ethereum takes minutes. You can't make an API wait that long.

🪙

Near-zero fees

Each Stellar transaction costs $0.0000001. Paying $0.001 for an API call doesn't work if the gas fee is $0.01.

💵

USDC — Stable value

Developers earn in USDC (USD Coin), not volatile crypto. $0.001 today is $0.001 tomorrow.

📜

Soroban smart contracts

Stellar's Soroban smart contract platform verifies each payment on-chain, making the entire flow trustless.

🌐 What is a Stellar wallet?

A Stellar wallet is like your bank account on the blockchain — but you own the private key (no bank involved). It's identified by a public address like GBZXN7PIRZGNMHGA7.... When you connect your wallet to PayGate, we can see your address but we never have access to your private key. You sign transactions locally on your device.

04The Platform

PayGate — The Middleware That Connects Everything

Building all of the above from scratch would take months. PayGate is a hosted proxy that handles the entire x402 flow for you. Think of it as a smart gateway that sits in front of any existing API.

Architecture Overview

Your APIAny HTTP endpoint
registers
PayGatePayment gateway
issues
Paywalled URLpaygate.app/api/x/...
AI Agent / AppSends request + payment
hits
PayGateVerifies payment on Stellar
proxies to
Your APIGets clean request

Payment Interception

PayGate intercepts every request, checks for a valid x402 payment signature before forwarding.

On-chain Verification

The Stellar transaction is verified against our Soroban smart contract in real time.

Instant Earnings

USDC goes directly to the developer's Stellar wallet. No escrow, no delays.

05For Builders

How to List Your API on PayGate

You already have an API. Maybe it's a weather endpoint, a data aggregator, or an AI model. Here's how you turn it into a paid service in under 5 minutes — no code changes needed.

Step 1

Connect Your Stellar Wallet

Click "Get Started" on the top right. You'll be asked to sign a challenge message with your Stellar wallet. This proves you own the wallet address — we never store your private key.

Don't have a Stellar wallet? You can create one free at stellar.org or use any compatible wallet like Freighter.
Step 2

Register Your API Endpoint

In your dashboard, click "New API". Fill in a name, description, your existing API's URL, and the price you want to charge per call in USDC.

Name: Weather API London
URL: https://your-backend.com/weather
Price: 0.001 USDC per call
Visibility: Public
Your real API URL is kept private. Callers only ever see the PayGate endpoint.
Step 3

Get Your Paywalled Endpoint

PayGate instantly generates a public endpoint for you. Share this URL — it's the one callers will use. Every request through it will require a valid Stellar micropayment.

https://paygate.app/api/x/weather-london
Step 4

Start Earning USDC

That's it! Every time someone calls your endpoint with a valid x402 payment, the USDC is sent to your Stellar wallet instantly. Check your dashboard for real-time analytics and earnings.

Earnings are visible in your dashboard. You can withdraw to any exchange or wallet that supports Stellar USDC.
06For Callers

How to Call a Paid API

Whether you're building an app or an AI agent, consuming a PayGate API requires just two things: an x402-compatible client and a funded Stellar wallet. No signup. No API key. Pay only for what you use.

Step 1

Try It Live — No Setup Needed

Go to the Marketplace and click "Try in Playground" on any API. Our playground environment has a pre-funded test wallet — you can see the full x402 payment flow happen in real time with zero setup.

Step 2

Fund Your Stellar Wallet

For production use, you need a Stellar wallet funded with USDC on testnet. You can get free testnet USDC using Stellar's Friendbot, or use real USDC on mainnet.

# Fund your testnet wallet (free)
curl "https://friendbot-testnet.stellar.org?addr=YOUR_WALLET_ADDRESS"
Step 3

Install the x402 Client

Use the open-source x402 client SDK. It wraps your standard fetch() calls and automatically handles the 402 payment negotiation in the background.

npm install x402-fetch

import { wrapFetch } from 'x402-fetch';
import { Keypair } from '@stellar/stellar-sdk';

// Your Stellar wallet keypair
const keypair = Keypair.fromSecret('YOUR_SECRET_KEY');
const fetch402 = wrapFetch(fetch, keypair);

// Make a normal API call — payment happens automatically
const res = await fetch402('https://paygate.app/api/x/weather-london');
const data = await res.json();
console.log(data); // { temp: 18, condition: "Cloudy" }
Step 4

Behind the Scenes

Here's what happens automatically when you call fetch402():

  • Your client sends a normal GET request
  • PayGate responds with 402 + payment details
  • The x402 client builds a $0.001 USDC Stellar transaction
  • Signs it with your wallet's private key (locally — never sent to us)
  • Retries the request with the payment signature in the header
  • PayGate verifies the signature on Stellar's blockchain
  • Your request is proxied to the real API
  • You receive the response data instantly
You're all caught up!

The Full Picture in 6 Bullets

1

API keys and subscriptions are a broken model for the agentic internet

2

The x402 protocol revives HTTP 402 as a machine-readable payment standard

3

Stellar is the ideal money rail — fast, cheap, and supports stable USDC

4

PayGate is a hosted proxy that wraps any existing API with x402 payments

5

Developers list their API, set a price, and earn USDC per call — no code changes

6

Callers use the x402-fetch SDK to pay micropayments automatically with any wallet

Ready to Try It?

Explore the live marketplace to see real APIs in action, or connect your wallet and list your first API — it takes 5 minutes.