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
2. Architecture & Flow
System Architecture
AI Agents
Autonomous
API Buyers
Manual
API Providers
Dashboard
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
3. For API Providers
Provider Workflow
Signup
Create account
Settings
Set payout wallet
Create API
Name & description
Add Endpoints
URL, method, price
Publish
Go live
Share Gateway URL
Your API is now live
Requests
Come in
Earnings
Accrue
Monitor
Dashboard
Paid Directly
USDC to your wallet
Step-by-Step Guide
Create Account
Sign up at https://market.apiosk.com/signup with email and password.
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)
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
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 liveShare Your Gateway URL
Your endpoint is accessible at:
Example: https://apioskgateway.fly.dev//acme/weather/current
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
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
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# .env AGENT_PRIVATE_KEY=0x...your-agent-private-key... GATEWAY_URL=https://gateway.apiosk.com NETWORK=base-sepolia # Use 'base' for production
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())// 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.
| Parameter | Type | Description |
|---|---|---|
gatewayUrl | string | Apiosk gateway URL |
privateKey | string | Agent wallet private key (hex) |
network | 'base' | 'base-sepolia' | Blockchain network (default: base-sepolia) |
maxRetries | number | Max 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
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...
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..."
})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/
/:providerSlug/:apiSlug/:endpointSlugMain proxy endpoint. Validates payment and forwards request to upstream API.
Headers:
X-Payment- Signed x402 payment token
Response (no payment):
402Payment RequiredX-Payment-Amount- Price in selected assetX-Payment-Asset- USDC, USDT, DAI, or ETHX-Payment-Network- base or base-sepolia
Response (with payment):
200+ Upstream responseX-Payment-Status- paid
/healthHealth check endpoint. Returns gateway status and configuration.
/provider/:providerId/earningsGet provider earnings summary (balance, total earned, total withdrawn).
/provider/:providerId/withdrawRequest withdrawal of earnings to provider's payout wallet.
/provider/:providerId/withdrawalsList withdrawal request history with status.
Error Codes
| Status | Description |
|---|---|
400 | Bad Request - Invalid parameters |
402 | Payment Required - No valid payment token provided |
404 | Endpoint not found or not published |
500 | Internal server error |
502 | Upstream API error - Provider's server issue |
7. Provider Management API
APIs for managing provider accounts, APIs, and endpoints programmatically.
/provider/:providerId/apisCreate a new API for the provider.
{
"name": "Weather API",
"slug": "weather",
"description": "Real-time weather data"
}/provider/:providerId/apisList all APIs owned by the provider.
/apis/:apiId/endpointsCreate 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
}/apis/:apiId/endpointsList 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
| Header | Direction | Description |
|---|---|---|
X-Payment | Request | Signed payment token from buyer |
X-Payment-Amount | Response (402) | Required payment amount |
X-Payment-Asset | Response (402) | Payment asset (USDC, USDT, DAI, ETH) |
X-Payment-Network | Response (402) | Blockchain network (base, base-sepolia) |
X-Payment-Status | Response (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
| Asset | Type | Description |
|---|---|---|
USDC | Stablecoin | USD Coin - Primary payment asset (recommended) |
USDT | Stablecoin | Tether USD |
DAI | Stablecoin | Dai Stablecoin |
ETH | Native | Ethereum (native gas token) |