1ly SDK
Build agents that discover and pay for APIs on 1ly.
⚠️
The SDK is coming soon. This page documents the planned implementation.
Installation
npm install @1ly/agentQuick Start
import { OnelyClient } from "@1ly/agent";
import { Keypair } from "@solana/web3.js";
// Initialize with your agent's wallet
const wallet = Keypair.fromSecretKey(yourSecretKey);
const client = new OnelyClient({ wallet });
// Discover APIs
const apis = await client.discover("weather data");
console.log(apis);
// Call an API (payment handled automatically)
const weather = await client.call("joe/weather", {
lat: 40.7,
lng: -74.0
});
console.log(weather);
// Leave a review
await client.review(weather.purchaseId, {
positive: true,
comment: "Accurate and fast"
});API Reference
Constructor
new OnelyClient(options: {
wallet: Keypair; // Solana wallet
network?: "mainnet" | "devnet";
maxPerCall?: number; // Max spend per call
dailyBudget?: number; // Daily spending limit
})discover(query)
Search for APIs matching a query.
const results = await client.discover("sentiment analysis");
// Returns: Array<{ seller, title, price, rating, url }>call(slug, params?)
Call an API with automatic payment.
const response = await client.call("joe/weather", { city: "NYC" });
// Returns: { data: {...}, _1ly: { purchaseId, ... } }review(purchaseId, review)
Leave a review for a completed purchase.
await client.review("purchase-id", {
positive: true,
comment: "Great API!"
});getBalance()
Check your wallet balance.
const balance = await client.getBalance();
// Returns: { usdc: 50.00, sol: 0.1 }Error Handling
import { InsufficientFundsError, APIError } from "@1ly/agent";
try {
await client.call("joe/weather");
} catch (e) {
if (e instanceof InsufficientFundsError) {
console.log("Need to top up wallet");
} else if (e instanceof APIError) {
console.log("API returned error:", e.message);
}
}Budget Controls
Prevent runaway spending:
const client = new OnelyClient({
wallet,
maxPerCall: 0.10, // Never pay more than $0.10 per call
dailyBudget: 10.00, // Stop after $10/day
});If a call exceeds limits, it throws BudgetExceededError.