> ## Documentation Index
> Fetch the complete documentation index at: https://hyperbrowser.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Search with X402

> Pay for individual web searches with a wallet

Query the web and get clean, structured search results using `POST https://api.hyperbrowser.ai/x402/web/search`. No Hyperbrowser account or API key is required. The price is calculated from your request options and returned in the payment requirements.

## Search the web with TypeScript

The X402 SDKs handle the payment challenge, wallet signature, and retry automatically. This example supports both EVM and Solana wallets.

### 1. Install dependencies

```bash theme={null}
npm install @x402/fetch @x402/core @x402/evm @x402/svm viem @solana/kit @scure/base dotenv
npm install --save-dev tsx
```

### 2. Configure your wallet

Set either or both keys in a `.env` file. Use a `0x`-prefixed EVM private key or a base58-encoded Solana 64-byte secret key, and fund the wallet with USDC on the network you intend to use.

```dotenv theme={null}
EVM_PRIVATE_KEY=0x...
SOLANA_PRIVATE_KEY=...
```

Set only one key to choose EVM or Solana. With both set, the client uses the first compatible payment option returned by the server.

### 3. Search the web

Save this as `search.ts`. If your keys are in `.env.agent`, replace `dotenv.config()` with `dotenv.config({ path: ".env.agent" })`.

```typescript theme={null}
import dotenv from "dotenv";
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client, x402HTTPClient } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { registerExactSvmScheme } from "@x402/svm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
import { createKeyPairSignerFromBytes } from "@solana/kit";
import { base58 } from "@scure/base";

dotenv.config();

async function main() {
  const evmKey = process.env.EVM_PRIVATE_KEY;
  const solanaKey = process.env.SOLANA_PRIVATE_KEY;
  if (!evmKey && !solanaKey) {
    throw new Error("Set EVM_PRIVATE_KEY or SOLANA_PRIVATE_KEY in .env");
  }

  const client = new x402Client();

  if (evmKey) {
    registerExactEvmScheme(client, {
      signer: privateKeyToAccount(evmKey as `0x${string}`),
    });
  }

  if (solanaKey) {
    const signer = await createKeyPairSignerFromBytes(base58.decode(solanaKey));
    registerExactSvmScheme(client, { signer });
  }

  const fetchWithPayment = wrapFetchWithPayment(fetch, client);
  const response = await fetchWithPayment(
    "https://api.hyperbrowser.ai/x402/web/search",
    {
      method: "POST",
      signal: AbortSignal.timeout(60_000),
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ query: "hyperbrowser browser automation" }),
    }
  );

  const data = await response.json();
  if (!response.ok) {
    throw new Error(
      `Search failed (${response.status}): ${JSON.stringify(data)}`
    );
  }

  console.log("Search result:", JSON.stringify(data, null, 2));

  const httpClient = new x402HTTPClient(client);
  console.log(
    "Payment settled:",
    httpClient.getPaymentSettleResponse((name) => response.headers.get(name))
  );
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

Run the example:

```bash theme={null}
npx tsx search.ts
```

<Accordion title="Payment flow with cURL">
  ### Request payment requirements

  Send a search request to receive a `402 Payment Required` response:

  ```bash theme={null}
  curl -i https://api.hyperbrowser.ai/x402/web/search \
    -H "Content-Type: application/json" \
    -d '{"query": "hyperbrowser browser automation"}'
  ```

  The `PAYMENT-REQUIRED` header contains base64-encoded JSON with the accepted networks, assets, amount, and recipient.

  ### Sign and retry

  Use your X402 client and wallet to generate a signed payment authorization from those requirements. Set `PAYMENT_SIGNATURE` to the encoded authorization returned by your client, then retry with the same request body:

  ```bash theme={null}
  curl --fail-with-body https://api.hyperbrowser.ai/x402/web/search \
    -H "Content-Type: application/json" \
    -H "PAYMENT-SIGNATURE: ${PAYMENT_SIGNATURE}" \
    -d '{"query": "hyperbrowser browser automation"}'
  ```

  The response contains the search status, query, and results with titles, URLs, and descriptions. The `PAYMENT-RESPONSE` header contains settlement information. See the [X402 overview](/docs/integrations/x402/overview#how-it-works) for the shared payment flow.
</Accordion>

Each request returns search results. To purchase a browser you can control directly, use [Browser Sessions](/docs/integrations/x402/sessions).

See the [Search API documentation](/docs/web/search) for the full parameter reference and examples, and the [X402 Search reference](/docs/api-reference/search-the-web-with-x402-payment) for payment headers and response schemas.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.