Discover and call tools
curl https://x402.slinkylayer.ai/.well-known/x402type DiscoveryDocument = {
version: number;
resources: string[];
};
const DISCOVERY_URL =
"https://x402.slinkylayer.ai/.well-known/x402";
export async function runWebSearch(
fetchWithPayment: typeof fetch,
query: string,
) {
const discoveryResponse = await fetch(DISCOVERY_URL, {
headers: { accept: "application/json" },
});
if (!discoveryResponse.ok) {
throw new Error(
"Tool discovery failed: " + discoveryResponse.status,
);
}
const catalog =
(await discoveryResponse.json()) as DiscoveryDocument;
const resourceUrl = catalog.resources.find((resource) =>
resource.endsWith("/web_search"),
);
if (!resourceUrl) {
throw new Error("web_search is not currently available");
}
const response = await fetchWithPayment(resourceUrl, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ query }),
});
if (!response.ok) {
throw new Error("Tool request failed: " + response.status);
}
return response.json();
}Last updated