import { Payments } from "@nevermined-io/payments";
const payments = Payments.getInstance({
nvmApiKey: process.env.NVM_API_KEY!, // your Nevermined API key
environment: "live", // or "sandbox" for testing
});
// 1. Mint x402 token scoped to an enrolled card
const { accessToken } = await payments.x402.getX402AccessToken(
"107134729016282785317688751027026876438402324055584221042936325851129895197441",
undefined,
{
scheme: "nvm:card-delegation",
delegationConfig: {
providerPaymentMethodId: "pm_...", // Stripe payment method, enrolled in Nevermined
spendingLimitCents: 1000, // >= $10 per call
durationSecs: 3600,
},
},
);
// 2. Exchange the token for (or top up) an Exa API key
const res = await fetch(
"https://admin-api.exa.ai/team-management/nevermined/purchase-key",
{ method: "POST", headers: { "payment-signature": accessToken } },
);
const { apiKey } = await res.json();
// 3. Use the key like any Exa API key
await fetch("https://api.exa.ai/search", {
method: "POST",
headers: { "x-api-key": apiKey, "Content-Type": "application/json" },
body: JSON.stringify({ query: "..." }),
});