Skip to content
NavenDocs
QuickstartAPI referenceOpen Naven
NavenDocs
Introduction
QuickstartHow x402 Payments WorkBuyer/Client GuideNaven CLISeller/Server Guide

Build with Naven

AI GatewayQuickstartJev evaluationsModels and pricingAPI referenceRetries and recovery

Payments

Resources

Naven Network
AI Gateway

Quickstart

Make a standard x402-paid Jev evaluation with USDG.

You need a wallet with USDG on Robinhood Chain mainnet. The wallet signs a token authorization; it does not send a separate manual transfer. You do not need a Naven account or a model-provider API key.

1. Check Jev availability

For an interactive first call, open the dedicated Jev playground. Choose an operations, risk, or trust-and-safety example, edit its state and question, and review the fixed evaluation price before signing.

For an integration, fetch the gateway catalog:

curl https://agents.naven.network/ai-gateway/v1/models

Check that evaluation.available is true. Review evaluation.amount and confirm the recipient in payment.payTo. Pin that recipient and a maximum amount in your application. Jev is an evaluation model, so it is described by evaluation rather than the text-model data array.

2. Request the x402 offer

Send the intended evaluation without a payment header:

curl https://agents.naven.network/ai-gateway/v1/evaluations \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "typesafe-ai/jev",
    "state": "A deployment failed twice after a migration. Rollback succeeded and no customer data was lost.",
    "questions": {
      "escalate": {
        "type": "boolean",
        "instructions": "Should this incident receive immediate human review?"
      }
    }
  }'

The endpoint returns HTTP 402 with the complete payment requirement in both the JSON body and the PAYMENT-REQUIRED header. No evaluation or settlement happens until the request is repeated with a valid PAYMENT-SIGNATURE.

3. Pay and receive the decision

Install the payment client:

bun add @x402/core@2.18.0 @x402/evm@2.18.0 viem

The following server-side example requests the offer, validates the recipient and spending limit, signs it, and repeats the same request. Keep private keys in secret storage and never include them in browser code; browser applications should use the connected wallet's signing methods instead.

import { x402Client, x402HTTPClient } from "@x402/core/client";
import { decodePaymentResponseHeader } from "@x402/core/http";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const endpoint = "https://agents.naven.network/ai-gateway/v1/evaluations";
const network = "eip155:4663";
const asset = "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168";
const privateKey = process.env.X402_PRIVATE_KEY;
const expectedPayTo = process.env.EXPECTED_PAY_TO;
const maximumAmount = BigInt(process.env.MAX_PAYMENT_ATOMIC ?? "0");

if (!/^0x[0-9a-fA-F]{64}$/.test(privateKey ?? ""))
  throw new Error("Set X402_PRIVATE_KEY.");
if (!/^0x[0-9a-fA-F]{40}$/.test(expectedPayTo ?? ""))
  throw new Error("Set EXPECTED_PAY_TO from the model catalog.");
if (maximumAmount <= 0n) throw new Error("Set MAX_PAYMENT_ATOMIC.");

const body = JSON.stringify({
  model: "typesafe-ai/jev",
  state: "A deployment failed twice after a migration.",
  questions: {
    escalate: {
      type: "boolean",
      instructions: "Should a human review this now?",
    },
  },
});

const challenge = await fetch(endpoint, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body,
});
if (challenge.status !== 402)
  throw new Error(`Expected HTTP 402, received ${challenge.status}`);

const offer = await challenge.json();
const payment = offer?.accepts?.[0];
if (
  offer?.x402Version !== 2 ||
  offer.resource?.url !== endpoint ||
  offer.accepts?.length !== 1 ||
  payment?.scheme !== "exact" ||
  payment.network !== network ||
  payment.asset?.toLowerCase() !== asset.toLowerCase() ||
  payment.payTo?.toLowerCase() !== expectedPayTo.toLowerCase() ||
  !/^\d+$/.test(payment.amount) ||
  BigInt(payment.amount) <= 0n ||
  BigInt(payment.amount) > maximumAmount ||
  payment.extra?.name !== "Global Dollar" ||
  payment.extra?.version !== "1"
) throw new Error("Payment offer failed validation.");

const client = new x402Client();
registerExactEvmScheme(client, {
  networks: [network],
  signer: privateKeyToAccount(privateKey),
});
const http = new x402HTTPClient(client);
const payload = await http.createPaymentPayload(offer);
const paymentHeaders = http.encodePaymentSignatureHeader(payload);

const response = await fetch(endpoint, {
  method: "POST",
  headers: { ...paymentHeaders, "Content-Type": "application/json" },
  body,
});
if (!response.ok)
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);

const evaluation = await response.json();
const receiptHeader = response.headers.get("PAYMENT-RESPONSE");
if (!receiptHeader) throw new Error("Missing payment receipt.");
const receipt = decodePaymentResponseHeader(receiptHeader);
if (!receipt.success || receipt.network !== network)
  throw new Error("Payment confirmation is incomplete.");

console.log(JSON.stringify({ evaluation, receipt }, null, 2));

Set X402_PRIVATE_KEY, EXPECTED_PAY_TO, and MAX_PAYMENT_ATOMIC, then run the script. A successful call returns typed Jev probabilities and an x402 settlement receipt. The current fixed evaluation amount is 3000 atomic units (0.003 USDG), but validate the live offer and keep your own spending cap.

For boolean, choice, and score request shapes, see Jev evaluations. For text generation, use the same payment flow with POST /chat/completions and a model from GET /models; see the API reference.

If the paid request times out, preserve its exact body and PAYMENT-SIGNATURE. Check payment status before creating another authorization. See Retries and recovery for failure semantics and recovery limits.

AI Gateway

Make probabilistic decisions with Jev or generate text, paid per successful call with USDG.

Jev evaluations

Turn state into typed probabilities for agent decisions.

On this page

1. Check Jev availability2. Request the x402 offer3. Pay and receive the decision