request.tsimport { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { wrapFetchWithPayment } from "@x402/fetch";
import { privateKeyToAccount } from "viem/accounts";
const signer = privateKeyToAccount(
process.env.EVM_PRIVATE_KEY as `0x${string}`,
);
const client = new x402Client().register(
"eip155:8453",
new ExactEvmScheme(signer),
);
const paidFetch = wrapFetchWithPayment(fetch, client);
const result = await paidFetch(
"https://transcript.melchiorlabs.com/v1/youtube/transcript",
{
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
url: "https://www.youtube.com/watch?v=…",
language: "en",
}),
},
);
console.log(await result.json());