const jobRes = await fetch(`${baseUrl}/generate/text`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
prompt: 'Write a welcome note for new Horizon users.',
webhookUrl: 'https://example.com/webhooks/horizon',
}),
});
if (jobRes.status === 402) {
const payment = await jobRes.json();
// Replay using Coinbase buyer quickstart:
// https://docs.cdp.coinbase.com/x402/quickstart-for-buyers
throw new Error(`Payment required: ${payment.accepts[0].resource}`);
}
const job = await jobRes.json();
console.log(job.jobId, job.statusUrl);