> For the complete documentation index, see [llms.txt](https://docs.slinky.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.slinky.network/developers/discover-and-call-tools.md).

# Discover and call tools

Read the discovery document when the application starts, when a cached resource returns `404`, or before a long-running agent begins a new job.

```shellscript
curl https://x402.slinkylayer.ai/.well-known/x402
```

The following example discovers the current `/web_search` resource. It accepts a payment-aware fetch function supplied by the caller, which keeps wallet setup separate from discovery.

<pre class="language-typescript"><code class="lang-typescript"><strong>type DiscoveryDocument = {
</strong>  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();
}
</code></pre>

The body illustrates a simple web-search call. Tool inputs can differ, so validate the request shape used by the selected resource before sending production traffic.

{% hint style="info" %}
**Keep signing material out of the browser**

Use a maintained x402 client in a server process or isolated signer. An autonomous agent should use a dedicated wallet with explicit spending limits and an allowlist of resources.
{% endhint %}
