For the past few weeks I've been building Yantrix — an agent-native API network where every tool call costs fractions of a cent in USDC, settled automatically on Base mainnet via x402.
Today it hit 58 tools and I want to share what I learned.
What is x402?
x402 is an emerging standard that revives the HTTP 402 "Payment Required" status code. When an agent calls a paid endpoint without payment, it gets back a 402 with instructions on how to pay. An x402-enabled client automatically signs a USDC microtransaction and retries — no credit cards, no API key billing, no invoices.
The economics: $0.001 per call. Agents can autonomously consume APIs and pay for them. No human in the loop.
What Yantrix covers
The 58 tools span 7 service groups:
Crypto — real-time price, trading signals, deep analysis, AI reports
Finance — stocks, company profiles, financials, forex, market overview
Web Extract — clean text, metadata, contacts, PDF, structured data, AI summaries
India Business — GST lookup, MCA21/CIN, business enrichment (this is a real gap in the market)
Agent Utility — Indic script transliteration (9 scripts), IFSC lookup, phone validation, timezone, pincode
Agent Registry — register agents with capabilities and DIDs, discover other agents
Agent Session — stateful workflow sessions with spend caps and call tracking
The architecture that makes it work
Each service is a single Python file. FastAPI + asyncpg + eth-account. Deployed on Railway. Here's the full pattern:
python# Single-file Railway service — no core/ dependency hell
import os, asyncpg
from fastapi import FastAPI
from contextlib import asynccontextmanager
DATABASE_URL = os.getenv("DATABASE_URL")
PORT = int(os.getenv("PORT", 8000))
_pool = None
async def get_pool():
global _pool
if _pool is None and DATABASE_URL:
_pool = await asyncpg.create_pool(DATABASE_URL, min_size=1, max_size=10)
return _pool
@asynccontextmanager
async def lifespan(app):
await run_migrations()
yield
if _pool: await _pool.close()
app = FastAPI(lifespan=lifespan)
if name == "main":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=PORT)
Key lesson: self-contained single files deploy reliably. I wasted days trying to share a core/ library across services in a monorepo. Railway builds each service in isolation — relative paths break. Single file = no path issues.
TrustLayer — every response is ECDSA signed
This is the part I'm most proud of. Every API response includes a _trust envelope:
json{
"data": { ... },
"_trust": {
"call_id": "ytx_abc123",
"endpoint": "/v1/agents/register",
"payload_hash": "sha256:def456...",
"timestamp": 1711234567,
"signer": "0x41A024...",
"signature": "0x3ad7f1..."
}
}
Agents can verify this signature cryptographically:
pythonfrom eth_account import Account
from eth_account.messages import encode_defunct
message = f"{call_id}:{endpoint}:sha256:{payload_hash}:{timestamp}"
msg = encode_defunct(text=message)
recovered = Account.recover_message(msg, signature=signature)
assert recovered.lower() == expected_signer.lower()
No other API marketplace does this. When an agent makes a decision based on data from Yantrix, there's cryptographic proof of what data it was given.
The MCP server is dynamic
Instead of hardcoding 58 tools in a TypeScript file, the MCP server fetches a registry JSON at startup:
typescriptconst REGISTRY_URL = "https://registry.yantrix.ai/mcp-registry.json";
// On startup, fetch all tools dynamically
const registry = await fetch(REGISTRY_URL).then(r => r.json());
// New APIs appear automatically on next host restart
This means adding a new API requires zero npm publishes. Update the registry JSON, done.
Agent Registry — agents registering themselves
The newest addition is an agent registry where AI agents can register their own capabilities:
bashcurl -X POST https://agent-registry.yantrix.ai/v1/agents/register \
-H "Content-Type: application/json" \
-d '{
"name": "GSTIN Intelligence Agent",
"endpoint_url": "https://my-agent.railway.app",
"wallet_address": "0x...",
"capabilities": [{
"name": "gstin_lookup",
"category": "data_enrichment",
"price_usdc": 0.001
}]
}'
Returns an agent_id and a W3C DID (did:yantrix:). Other agents can discover it:
bashGET /v1/agents/?capability=gstin_lookup&status=active
This is the foundation for agent-to-agent commerce — Relay, the next layer I'm building.
Agent Session — tracking multi-step workflows
For workflows that make multiple API calls, sessions track everything:
bash# Create session with $1 spend cap
POST /v1/sessions/
{"ttl_seconds": 3600, "max_spend_usdc": 1.0}
Record each call
POST /v1/sessions/{id}/calls
{"service": "udbavam", "endpoint": "/v1/gstin", "price_usdc": 0.002}
Get analytics
GET /v1/sessions/{id}/analytics
→ {total_calls: 47, total_spend_usdc: 0.094, success_rate: 97.8}
Sessions auto-abort if the spend cap is hit. No surprise charges.
How to use it
Install the MCP server:
bashnpx @yantrixai/mcp
Or add to Claude Desktop:
json{
"mcpServers": {
"yantrix": {
"command": "npx",
"args": ["@yantrixai/mcp"]
}
}
}
All 58 tools are available immediately. Paid tools return a x402_payment_required response until you configure an x402-enabled wallet.
Full API reference: https://yantrix.ai/llms.txt
What's next
Yantrix Relay — agent-to-agent micropayment mesh. When Agent A needs something Agent B offers, Yantrix brokers and settles in USDC. I take 2-5% of every settlement. Currently building the Capability Discovery and Settlement Record services.
TrustLayer Protocol — spinning out the ECDSA signing as an open standard. Any API provider can implement it. trustlayer-verify npm package coming soon.
If you're building with AI agents and want to try x402 micropayments, the registry is at https://registry.yantrix.ai/mcp-registry.json and everything is open at https://github.com/yantrix-ai.
Happy to answer questions about the x402 implementation, the Railway single-file pattern, or the agent registry design.
Tags: #ai #python #web3 #agents #mcp #x402 #blockchain #api[]
Top comments (0)