@agentindex/core
v0.1.1
Published
The Layer - One SDK for every x402 endpoint. Discovery, routing, payments, failover.
Maintainers
Readme
@agentindex/core
The Layer — One SDK for every x402 endpoint.
We're Cloudflare for the agent economy.
Install
npm install @agentindex/coreUsage
import { AgentIndexClient } from "@agentindex/core";
const client = new AgentIndexClient({
privateKey: process.env.WALLET_KEY,
budgetLimit: 10.00, // Max $10 spending
});
// That's it. Call ANY x402 endpoint.
const weather = await client.call({
capability: "weather",
params: { location: "miami" }
});
const price = await client.call({
capability: "crypto-price",
params: { token: "ETH" }
});
const analysis = await client.call({
capability: "ai-sentiment",
params: { text: "Bitcoin is mooning!" }
});What We Handle
| Feature | You Write | We Handle |
|---------|-----------|-----------|
| Discovery | capability: "weather" | Find best endpoint |
| Routing | One line | Route through Layer |
| Payment | Nothing | x402 + USDC |
| Failover | Nothing | Auto-retry |
| Caching | Nothing | Smart cache |
| Budget | budgetLimit: 10 | Track spending |
API
new AgentIndexClient(config)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| privateKey | string | required | Wallet private key |
| budgetLimit | number | 10.00 | Max USD to spend |
| chain | string | "base" | Payment chain |
| minTier | "A"/"B"/"C" | "C" | Minimum endpoint quality |
| maxPricePerCall | number | 1.00 | Max price per call |
| caching | boolean | true | Enable response caching |
| maxRetries | number | 3 | Failover attempts |
| debug | boolean | false | Enable logging |
client.call(options)
const result = await client.call({
capability: "weather", // What you need
params: { location: "miami" }, // Your params
maxPrice: 0.01, // Optional: override max price
noCache: false, // Optional: skip cache
timeout: 30000, // Optional: timeout ms
});
// Result
{
data: { temperature: 75, ... },
endpoint: { url: "...", tier: "A", ... },
pricePaid: 0.005,
cached: false,
latencyMs: 234,
txHash: "0x...",
budgetRemaining: 9.995
}client.discover(options)
Find endpoints without calling them:
const endpoints = await client.discover({
capability: "crypto-price",
maxPrice: 0.01,
minTier: "A",
verifiedOnly: true,
});client.getBudget()
const budget = client.getBudget();
// { limit: 10, spent: 0.25, remaining: 9.75, callCount: 5, percentUsed: 2.5 }Why The Layer?
Before: Your bot discovers endpoint → calls endpoint directly → pays endpoint
After: Your bot uses our SDK → we discover, route, pay, cache, failover → you get data
For Bots
- One line of code, any x402 endpoint
- Automatic discovery, payment, failover
- Budget controls, caching, smart routing
- We handle the complexity
For Endpoints
- All traffic routes through us
- Get verified for more traffic
- Analytics on who's calling you
- Premium placement available
Links
- Agent Index: https://theagentindex.app
- x402 Protocol: https://x402.org
- GitHub: https://github.com/CIII-glitch/agentindex-core
License
MIT
