Docs

Documentation

Complete guide to monetizing APIs and enabling autonomous AI agent payments with Apiosk.

1. Platform Overview

What is Apiosk?

Apiosk is a complete API marketplace platform that enables developers and companies to monetize their APIs using cryptocurrency (USDC stablecoin on the Base network). It implements the x402 protocol — an HTTP-based standard for machine-to-machine micropayments, designed specifically for autonomous AI agents.

Key Components

Gateway

Payment-processing proxy server that validates x402 payments and forwards requests to upstream APIs.

Market

Web dashboard for providers to register APIs, manage endpoints, track earnings, and withdraw funds.

Agent Client

Library for AI agents to make autonomous paid API calls with automatic payment signing.

Dashboard

Real-time analytics, earnings tracking, and API management in one place.

Supported Features

Per-request pricing
Multi-asset support
Testnet & Mainnet
Real-time earnings
Instant withdrawals
Request logging
AI agent wallets
All HTTP methods

2. Architecture & Flow

System Architecture

AI Agents

Autonomous

API Buyers

Manual

API Providers

Dashboard

APIOSK GATEWAY
āœ“

x402 Validation

$

Payment Processing

→

Request Forwarding

šŸ“Š

Earnings Tracking

Upstream APIs

Your Servers

  • • REST APIs
  • • GraphQL
  • • Any HTTP endpoint

Base Network

USDC Payments

  • • Mainnet (production)
  • • Sepolia (testnet)

Payment Flow (x402 Protocol)

AI Agent / Buyer

Gateway

Upstream API

1GET /provider/api/endpoint
2402 Payment Required
X-Payment-Amount: 0.01
X-Payment-Asset: USDC
X-Payment-Network: base
Agent auto-signs payment
3GET /provider/api/endpoint
X-Payment: <signed-token>
4Gateway processes
Validate payment
Credit provider
Forward request
5GET upstream-url
6Response data
7200 OK
X-Payment-Status: paid
+ Response data

3. For API Providers

Provider Workflow

1

Signup

Create account

2

Settings

Set payout wallet

3

Create API

Name & description

4

Add Endpoints

URL, method, price

5

Publish

Go live

Share Gateway URL

Your API is now live

https://apioskgateway.fly.dev//your-slug/api/endpoint
šŸ“„

Requests

Come in

šŸ’°

Earnings

Accrue

šŸ“Š

Monitor

Dashboard

Paid Directly

USDC to your wallet

Step-by-Step Guide

1

Create Account

Sign up at https://market.apiosk.com/signup with email and password.

2

Configure Provider Profile

In Settings, configure your provider profile:

  • Provider Name: Your display name
  • Provider Slug: URL identifier (e.g., "acme" becomes /acme/...)
  • Payout Wallet: Ethereum address for withdrawals (Base network)
3

Create an API

Navigate to APIs → New API and provide:

  • Name: Descriptive name (e.g., "Weather API")
  • Slug: URL path segment (e.g., "weather")
  • Description: What your API does
  • Icon: Optional icon for the marketplace
4

Add Endpoints

Each endpoint represents a monetized API route:

Endpoint Configuration:
ā”œā”€ā”€ Slug:           "current"           // URL path
ā”œā”€ā”€ Method:         "GET"               // HTTP method
ā”œā”€ā”€ Upstream URL:   "https://api.weather.com/v1/current"
ā”œā”€ā”€ Price:          "0.001"             // USDC per request
ā”œā”€ā”€ Asset:          "USDC"              // Payment asset
ā”œā”€ā”€ Network:        "base"              // Blockchain network
│
ā”œā”€ā”€ Advanced Options:
│   ā”œā”€ā”€ Request Headers:    {"Authorization": "Bearer xxx"}
│   ā”œā”€ā”€ Forward Body:       true/false
│   └── Forward Headers:    true/false
│
└── Published:      true/false          // Toggle to go live
5

Share Your Gateway URL

Your endpoint is accessible at:

https://apioskgateway.fly.dev//provider-slug/api-slug/endpoint-slug

Example: https://apioskgateway.fly.dev//acme/weather/current

6

Monitor & Get Paid

Track earnings on your dashboard. Each payment is sent directly to your wallet — no withdrawal needed.

4. For AI Agents

Apiosk enables AI agents to pay for APIs autonomously using the x402 protocol. When an agent receives a 402 response, it automatically signs a payment and retries — no human intervention required.

Agent Payment Architecture

AI AGENT SYSTEM

Agent Logic

Your Code

Agent Client

x402 SDK

Agent Wallet

Private Key

Automatic payment signing on 402 response

HTTP Request + X-Payment

Apiosk Gateway

Validate & Forward Request

Installation

npm install viem

The agent client uses viem for wallet operations and payment signing.

Complete Setup

Step 1: Create Agent Wallet
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'

// Generate a dedicated wallet for your agent
const privateKey = generatePrivateKey()
const account = privateKeyToAccount(privateKey)

console.log('Agent Address:', account.address)
console.log('Private Key:', privateKey)  // Store securely!

// Fund this wallet with USDC on Base network
Step 2: Environment Configuration
# .env
AGENT_PRIVATE_KEY=0x...your-agent-private-key...
GATEWAY_URL=https://gateway.apiosk.com
NETWORK=base-sepolia   # Use 'base' for production
Step 3: Initialize Agent Client
import { createAgent } from './agent-client'

const agent = createAgent({
  gatewayUrl: process.env.GATEWAY_URL!,
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  network: 'base-sepolia'  // or 'base' for mainnet
})

// Verify initialization
console.log('Agent wallet:', agent.getAddress())
Step 4: Make Paid API Calls
// The agent handles 402 responses and payments automatically

// GET request
const weather = await agent.callApi('/acme/weather/current', {
  method: 'GET'
})

// POST request with body
const completion = await agent.callApi('/openai/gpt4/completion', {
  method: 'POST',
  body: {
    prompt: 'Explain quantum computing',
    max_tokens: 100
  }
})

// Access response data
console.log('Data:', completion.data)
console.log('Paid:', completion.paymentInfo.amount, 'USDC')

Agent Client API Reference

createAgent(config)

Creates a new agent instance with automatic payment capabilities.

ParameterTypeDescription
gatewayUrlstringApiosk gateway URL
privateKeystringAgent wallet private key (hex)
network'base' | 'base-sepolia'Blockchain network (default: base-sepolia)
maxRetriesnumberMax retry attempts (default: 3)
agent.callApi(endpoint, options?)

Makes a paid API call with automatic payment handling.

const result = await agent.callApi('/provider/api/endpoint', {
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
  body?: object,                    // JSON request body
  headers?: Record<string, string>, // Additional headers
  timeout?: number                  // Timeout in ms (default: 30000)
})

// Returns:
interface ApiResponse<T> {
  data: T                // Response data from upstream API
  paymentInfo: {
    amount: string       // Amount paid in USDC
    txHash?: string      // Transaction hash (if available)
  }
}
agent.getAddress()

Returns the agent's wallet address (useful for funding and monitoring).

Security Best Practices

Wallet Isolation

Use dedicated wallets per agent. Never share wallets between agents or with personal funds.

Spending Limits

Fund agents with only what they need. Implement soft limits in your agent code.

Key Management

Store private keys in environment variables or a secrets manager. Rotate periodically.

Testnet First

Always develop on Base Sepolia before using real USDC on mainnet.

5. For API Buyers (Manual)

If you're not using an AI agent, you can still make paid API calls manually using any x402-compatible client.

Manual Payment Flow

1. Get Pricing Info
curl https://gateway.apiosk.com/provider/api/endpoint

# Response: 402 Payment Required
# Headers:
#   X-Payment-Amount: 0.01
#   X-Payment-Asset: USDC
#   X-Payment-Network: base
#   X-Payment-Recipient: 0x...marketplace-wallet...
2. Create Payment Token

Use an x402 client library to create a signed payment token:

// Using x402 client
const payment = await x402.createPayment({
  amount: "0.01",
  asset: "USDC",
  network: "base",
  recipient: "0x...marketplace-wallet..."
})
3. Make Paid Request
curl -X GET "https://gateway.apiosk.com/provider/api/endpoint" \
  -H "X-Payment: <your-x402-payment-token>"

# Response: 200 OK
# Headers:
#   X-Payment-Status: paid
# Body: <API response data>

6. Gateway API Reference

The Gateway handles all payment validation and request proxying. Base URL: https://apioskgateway.fly.dev/

ANY/:providerSlug/:apiSlug/:endpointSlug

Main proxy endpoint. Validates payment and forwards request to upstream API.

Headers:

  • X-Payment - Signed x402 payment token

Response (no payment):

  • 402 Payment Required
  • X-Payment-Amount - Price in selected asset
  • X-Payment-Asset - USDC, USDT, DAI, or ETH
  • X-Payment-Network - base or base-sepolia

Response (with payment):

  • 200 + Upstream response
  • X-Payment-Status - paid
GET/health

Health check endpoint. Returns gateway status and configuration.

GET/provider/:providerId/earnings

Get provider earnings summary (balance, total earned, total withdrawn).

POST/provider/:providerId/withdraw

Request withdrawal of earnings to provider's payout wallet.

GET/provider/:providerId/withdrawals

List withdrawal request history with status.

Error Codes

StatusDescription
400Bad Request - Invalid parameters
402Payment Required - No valid payment token provided
404Endpoint not found or not published
500Internal server error
502Upstream API error - Provider's server issue

7. Provider Management API

APIs for managing provider accounts, APIs, and endpoints programmatically.

POST/provider/:providerId/apis

Create a new API for the provider.

{
  "name": "Weather API",
  "slug": "weather",
  "description": "Real-time weather data"
}
GET/provider/:providerId/apis

List all APIs owned by the provider.

POST/apis/:apiId/endpoints

Create a new endpoint for an API.

{
  "slug": "current",
  "method": "GET",
  "upstream_url": "https://api.weather.com/v1/current",
  "price_amount": "0.001",
  "price_asset": "USDC",
  "price_network": "base",
  "description": "Get current weather",
  "published": true,
  "request_headers": {"Authorization": "Bearer xxx"},
  "forward_body": false,
  "forward_headers": false
}
GET/apis/:apiId/endpoints

List all endpoints for an API.

8. x402 Protocol

Apiosk implements the x402 protocol — an open standard for machine-to-machine payments over HTTP, designed for the agentic economy.

Why x402?

HTTP-Native

Uses standard HTTP 402 status code

Machine-Friendly

Designed for autonomous AI agents

Micropayment-Ready

Supports fractions of a cent

Open Standard

Interoperable with growing ecosystem

Protocol Headers

HeaderDirectionDescription
X-PaymentRequestSigned payment token from buyer
X-Payment-AmountResponse (402)Required payment amount
X-Payment-AssetResponse (402)Payment asset (USDC, USDT, DAI, ETH)
X-Payment-NetworkResponse (402)Blockchain network (base, base-sepolia)
X-Payment-StatusResponse (200)Payment confirmation (paid)

9. Networks & Assets

Supported Networks

Base (Mainnet)

Production network for real payments.

Chain ID: 8453

Base Sepolia (Testnet)

Testing network with test USDC.

Chain ID: 84532

Supported Assets

AssetTypeDescription
USDCStablecoinUSD Coin - Primary payment asset (recommended)
USDTStablecoinTether USD
DAIStablecoinDai Stablecoin
ETHNativeEthereum (native gas token)
Get started

Ready to monetize your APIs?

Join the agentic economy. Start accepting AI payments today.