Dexter
Dexter
Docs

API Discovery

The SDK includes a client for the Dexter marketplace that lets agents and applications discover x402 paid APIs programmatically. Search by keyword, filter by price and network, sort by quality or volume, then call the discovered endpoints directly with the same SDK.

Best Fit

Use API Discovery when:

  • an AI agent needs to find tools and data sources at runtime
  • you want to compare pricing across providers
  • you need to filter APIs by network, category, or quality score
  • you're building an agent that discovers and pays for capabilities on its own

Minimal Example

import { searchAPIs } from '@dexterai/x402/client';
 
const results = await searchAPIs({ query: 'sentiment analysis' });
 
for (const api of results) {
  console.log(`${api.name}: ${api.price} — ${api.description}`);
  console.log(`  Quality: ${api.qualityScore}, Verified: ${api.verified}`);
}

What This Does

  1. Queries the Dexter marketplace at x402.dexter.cash
  2. Returns typed DiscoveredAPI[] with pricing, quality scores, seller info, and verification status
  3. Each result's url can be passed directly to wrapFetch or createX402Client.fetch

Search Options

const results = await searchAPIs({
  query: 'token price',          // Free-text search
  category: 'defi',             // Filter by category
  network: 'solana',            // Filter by payment network
  maxPrice: 0.10,               // Max price per call in USDC
  verifiedOnly: true,           // Only quality-verified endpoints (score 75+)
  sort: 'quality_score',        // Sort order
  limit: 10,                    // Max results (default 20, max 50)
});

Sort options: marketplace (default), relevance, quality_score, settlements, volume, recent

Network options: solana, base, polygon, arbitrum, optimism, avalanche

Response Shape

Each DiscoveredAPI includes:

interface DiscoveredAPI {
  name: string;              // API name
  url: string;               // Full URL — pass to wrapFetch directly
  method: string;            // HTTP method (GET, POST)
  price: string;             // Formatted price ('$0.05')
  priceUsdc: number | null;  // Raw price in USDC
  network: string | null;    // Payment network
  description: string;       // What the API does
  category: string;          // Category (defi, ai, data, etc.)
  qualityScore: number | null;   // 0-100 quality score
  verified: boolean;         // Passed quality verification
  totalCalls: number;        // Total settlements
  totalVolume: string | null;    // Formatted volume ('$1,234.56')
  seller: string | null;     // Seller name
  sellerReputation: number | null; // Seller reputation score
  authRequired: boolean;     // Whether auth is needed beyond payment
  lastActive: string | null; // Last settlement timestamp
}

Discover Then Pay

The discovery + payment flow in one script:

import { searchAPIs, wrapFetch } from '@dexterai/x402/client';
 
const x402Fetch = wrapFetch(fetch, {
  walletPrivateKey: process.env.SOLANA_PRIVATE_KEY,
});
 
// Find the cheapest verified sentiment API
const apis = await searchAPIs({
  query: 'sentiment',
  verifiedOnly: true,
  sort: 'quality_score',
});
 
if (apis.length > 0) {
  const best = apis[0];
  console.log(`Using ${best.name} at ${best.price}`);
  const response = await x402Fetch(best.url);
  const data = await response.json();
}

Combining with Budget Accounts

Let an agent discover and pay within a budget:

import { searchAPIs, createBudgetAccount } from '@dexterai/x402/client';
 
const agent = createBudgetAccount({
  walletPrivateKey: key,
  budget: { total: '10.00', perRequest: '0.50' },
});
 
const apis = await searchAPIs({ query: 'market data', maxPrice: 0.50 });
 
for (const api of apis) {
  try {
    const res = await agent.fetch(api.url);
    console.log(`Called ${api.name}, spent so far: ${agent.spent}`);
  } catch (err) {
    if (err.code === 'amount_exceeds_max') break; // Budget exhausted
  }
}

Custom Marketplace URL

By default, searchAPIs queries the Dexter marketplace. You can point to a different marketplace:

const results = await searchAPIs({
  query: 'data',
  marketplaceUrl: 'https://custom-marketplace.example.com/api/resources',
});

When To Use Something Else

  • If you already know the URL, skip discovery and call it directly with wrapFetch
  • For browser-based discovery UIs, use the marketplace at dexter.cash
  • For MCP tool discovery, use @dexterai/opendexter which wraps the same search as an MCP tool

On this page