# Competitive brief (client-side workflow)

**Job:** Search → scrape top result → summarize with Workers AI chat/fast.

**Not a `?bundle=` filter** — three atomic x402 calls the agent orchestrates. No server-side recipe route.

## Prerequisites

```bash
npm install @x402/fetch @x402/core @x402/evm viem
```

## Script

```typescript
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const signer = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const client = new x402Client();
client.register("eip155:*", new ExactEvmScheme(signer));
const pay = wrapFetchWithPayment(fetch, client);

// 1 — Tavily search
const searchRes = await pay("https://search.gedx402.com/v1/tavily/search", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ query: "Acme Corp product launch 2026", max_results: 3 }),
});
const { results } = await searchRes.json();
const topUrl = results[0]?.url ?? "https://example.com";

// 2 — Firecrawl scrape
const scrapeRes = await pay("https://browser.gedx402.com/v1/firecrawl/scrape", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ url: topUrl }),
});
const { markdown } = await scrapeRes.json();

// 3 — Summarize (chat/fast on chat shard)
const summaryRes = await pay("https://chat.gedx402.com/v1/chat/fast", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    messages: [
      { role: "user", content: `Summarize this competitive intel in 5 bullets:\n\n${markdown?.slice(0, 12000)}` },
    ],
    max_tokens: 512,
  }),
});
const brief = await summaryRes.json();
console.log(brief);
```

## awal alternative

```bash
npx awal@2.12.0 x402 pay https://search.gedx402.com/v1/tavily/search --body '{"query":"Acme Corp","max_results":3}'
# … then scrape + chat/fast with scraped markdown
```

## Optional: Code Mode MCP

When Cloudflare Code Mode LOADER is prod-ready, expose this script via hub MCP (`ged-x402` codemode agent). Until then, integrators use the script above.
