Skip to content
This repository was archived by the owner on Sep 13, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Send end users through the **[JavaScript SDK](../sdks/javascript)** or **[Hosted

The SDK's `getGate()` / `fulfillGate()` wrap the gate endpoints above.

> **Scope note:** This reference covers the core HTTP proof and verification surface. Gate endpoints (`/api/v1/profile/gates/{gateId}`, `.../fulfill`, `/api/v1/profile/gates/discoverable`) and `POST /api/v1/payments/verify` (x402 pay-per-call settlement) are product checkout endpoints documented in [Hosted Gate Checkout](../platform/hosted-gate-checkout) and [x402](../platform/x402); they are intentionally not included in the OpenAPI reference on the API Reference tab.
> **Scope note:** This reference covers the core HTTP proof and verification surface. Gate endpoints (`/api/v1/profile/gates/{gateId}`, `.../fulfill`, `/api/v1/profile/gates/discoverable`) are product checkout endpoints documented in [Hosted Gate Checkout](../platform/hosted-gate-checkout). Standards-native x402 v2 payment for `GET /api/v1/proofs/check` is documented in [x402](../platform/x402).

**Same-origin in the product app:** `https://neus.network/api/v1/gates/{gateId}` and `.../fulfill` return the same gate contract for browser calls. Server integrations should call `api.neus.network` paths directly (or use the SDK).

Expand Down
4 changes: 2 additions & 2 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Three drop-in paths cover most products. Pick the one that matches what you are
<Card title="Connect an assistant" icon="plug" href="./install">
One command: `neus setup` — same account and receipts in Cursor, Claude Code, Codex, and VS Code.
</Card>
<Card title="Check agents before action" icon="robot" href="./agents/agent-verification-flow">
Agent identity and permission receipts a runtime can check before tools run.
<Card title="Control agent actions" icon="robot" href="./agents/agent-verification-flow">
Portable agent identity, context, and control across any runtime.
</Card>
</CardGroup>

Expand Down
28 changes: 27 additions & 1 deletion docs/openapi/public-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@
"get": {
"operationId": "proofCheck",
"summary": "Check gate eligibility or proof criteria (server-side)",
"description": "Primary server-side integrator endpoint for access control. Pass gateId from your deployed gate, or explicit verifier/criteria filters. Returns eligible plus matched proof references without exposing private proof payloads.",
"description": "Primary server-side integrator and x402 v2 resource for pre-action trust decisions. Pass gateId from your deployed gate, or explicit verifier/criteria filters. Unpaid public calls receive HTTP 402 with base64-encoded PAYMENT-REQUIRED instructions; retry the identical request with PAYMENT-SIGNATURE. Returns eligible plus matched proof references without exposing private proof payloads.",
"tags": [
"Proofs",
"Gates"
Expand Down Expand Up @@ -2602,6 +2602,14 @@
"$ref": "#/components/schemas/GateCheckResponse"
}
}
},
"headers": {
"PAYMENT-RESPONSE": {
"description": "Base64-encoded x402 v2 settlement result when the request was paid with x402",
"schema": {
"type": "string"
}
}
}
},
"400": {
Expand All @@ -2624,6 +2632,24 @@
}
}
},
"402": {
"description": "x402 v2 payment required",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"headers": {
"PAYMENT-REQUIRED": {
"description": "Base64-encoded x402 v2 PaymentRequired object",
"schema": {
"type": "string"
}
}
}
},
"500": {
"description": "Server error",
"content": {
Expand Down
2 changes: 1 addition & 1 deletion docs/platform/billing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ For a dedicated agent account, create identity first, then send the user through

## When credits run out

Billable calls return **402** with a quote. Complete payment and retry with `PAYMENT-SIGNATURE`.
The public trust-check resource supports standards-native x402 v2 payment. See [x402 pay-per-call](./x402) for the payable URL, transport headers, and retry flow.

## Advanced server integration

Expand Down
125 changes: 61 additions & 64 deletions docs/platform/x402.mdx
Original file line number Diff line number Diff line change
@@ -1,97 +1,94 @@
---
title: x402 pay-per-call
description: Charge per request for APIs and agents — a signed quote on 402, pay, then retry with one header.
description: Pay for NEUS trust checks with x402 v2 and USDC on Base — no account or prepaid balance required.
icon: coins
---

x402 turns any billable NEUS call into pay-as-you-go. When prepaid credits cannot cover a request, NEUS returns **HTTP 402** with a signed quote. Pay the quote, then retry the **same request** with one header. It is built for agents and machine-to-machine APIs that settle value as they go — no subscription, no human in the loop.
NEUS exposes a standards-native x402 v2 resource for agents and server applications that need a trust decision before taking an action. A caller can discover the price, authorize USDC, retry the same request, and receive the result without creating a NEUS account.

## Flow
## Payable HTTP resource

The canonical x402 resource is:

```text
GET https://api.neus.network/api/v1/proofs/check
```

Pass either a deployed `gateId` or explicit receipt criteria. This example checks whether an account has a reusable `ownership-basic` receipt:

```bash
curl -i --get https://api.neus.network/api/v1/proofs/check \
--data-urlencode "address=0xYOUR_ACCOUNT" \
--data-urlencode "verifierId=ownership-basic"
```

<Note>
`https://mcp.neus.network/mcp` is the authenticated MCP transport for MCP clients. HTTP x402 clients should use the `api.neus.network` resource above.
</Note>

## Standards-native v2 flow

<Steps>
<Step title="Call the API">
Make your normal request (for example `POST /api/v1/verification`).
<Step title="Request the resource">
Send the final HTTP method, URL, query parameters, and body you intend to use.
</Step>
<Step title="Get a 402 + quote">
If credits are short, NEUS responds **402** with a quote in the body and the **`PAYMENT-REQUIRED`** response header.
<Step title="Read the payment requirements">
An unpaid request returns HTTP `402`. The `PAYMENT-REQUIRED` response header contains a base64-encoded x402 v2 `PaymentRequired` object with `x402Version: 2`, the resource, and an `accepts` array.
</Step>
<Step title="Pay the quote">
Settle in USDC (or native ETH) via `POST /api/v1/payments/verify`. NEUS returns a one-time payment receipt.
<Step title="Authorize payment">
Select the advertised `exact` requirement and let an x402 v2 client create the payment payload. NEUS currently accepts USDC settlement on Base for production.
</Step>
<Step title="Retry with the receipt">
Repeat the original call with the receipt in the **`PAYMENT-SIGNATURE`** header. The call now succeeds.
<Step title="Retry the identical request">
Repeat the same request with the base64-encoded payment payload in `PAYMENT-SIGNATURE`. NEUS verifies it before execution and settles it after a successful call.
</Step>
<Step title="Keep the settlement receipt">
A successful paid response includes `PAYMENT-RESPONSE`, a base64-encoded settlement result containing the network and transaction reference.
</Step>
</Steps>

## The 402 response

The body carries `error.code: "INSUFFICIENT_CREDITS"` and an `x402` block you can act on directly:

```json
{
"success": false,
"error": { "code": "INSUFFICIENT_CREDITS", "remaining": 0, "required": 4 },
"x402": {
"scheme": "x402",
"requiredCredits": 4,
"remainingCredits": 0,
"quote": {
"quoteId": "…",
"amountUSD": 0.01,
"amountCents": 1,
"creditsNeeded": 4,
"exp": 1713312300000
},
"pay": { "pricing": "/api/v1/payments/pricing" },
"receiptHeader": "PAYMENT-SIGNATURE"
}
}
```
The three x402 v2 transport headers are:

The same quote is also sent as JSON in the `PAYMENT-REQUIRED` response header. `exp` is a millisecond timestamp — quotes are short-lived, so pay and retry promptly.
| Header | Direction | Purpose |
| --- | --- | --- |
| `PAYMENT-REQUIRED` | NEUS → caller | Base64-encoded price and payment requirements on HTTP 402 |
| `PAYMENT-SIGNATURE` | Caller → NEUS | Base64-encoded payment payload on the retry |
| `PAYMENT-RESPONSE` | NEUS → caller | Base64-encoded settlement result |

## Pay and retry

```bash
# 1. Original call returns 402 with the quote above.
# 2. Settle the quote (USDC or ETH), then retry with the receipt:
curl -X POST https://api.neus.network/api/v1/verification \
-H "Content-Type: application/json" \
-H "PAYMENT-SIGNATURE: <receipt-from-payments-verify>" \
-d '{ /* the same body as the original request */ }'
```
Do not parse these headers as raw JSON. Use an x402 v2 client or the header helpers from `@x402/core/http`.

Get the receipt by settling the quote through `POST /api/v1/payments/verify` (`type: "x402"`). The successful response returns the receipt token and a `PAYMENT-RESPONSE` header. Each receipt is **single-use** — reusing one is rejected.
## Bazaar discovery

## Payment methods
The trust-check resource declares the official x402 v2 Bazaar extension with:

| Rail | Where it settles |
|------|------------------|
| **USDC** | Base mainnet (`eip155:8453`), with Ethereum mainnet as fallback |
| **Native ETH** | NEUS treasury |
- a semantic description oriented around pre-action trust and authority decisions;
- a realistic query example;
- JSON Schema for supported input fields;
- output metadata, schema, and an example result;
- an `exact` USDC payment requirement on a CAIP-2 Base network.

Card (Stripe) is **not** used for x402 API billing — it is available for [gate checkout](./hosted-gate-checkout). Live unit, minimum, and maximum pricing: `GET /api/v1/payments/pricing`.
Compatible facilitators can index the declared resource after a paid call settles. Discovery catalogs refresh asynchronously, so a newly settled resource may not appear immediately.

## Agents that pay on their own

Pair x402 with an agent permission receipt to set a spending cap. The receipt identifies the agent, records who approved it, and limits how much it may pay.
Pair x402 with an `agent-delegation` receipt to constrain autonomous spend:

- Grant `agent-delegation` with `scope: "payments:x402"` and a `maxSpend` cap.
- `maxSpend` is a whole-number string in token base units — for USDC (6 decimals), 25 USDC is `"25000000"`. Use `toAgentDelegationMaxSpend('25', 6)` from `@neus/sdk`.
- The agent can pay per call up to the cap; spend beyond it is refused.
- set `scope: "payments:x402"`;
- restrict `allowedPaymentTypes` to `x402`;
- store `maxSpend` as a whole-number string in token base units (USDC has 6 decimals);
- reject payment when the requested amount exceeds the remaining delegated cap.

Details: [Agent permissions](../agents/agent-delegation).
Use `toAgentDelegationMaxSpend('25', 6)` from `@neus/sdk` to represent a 25 USDC cap as `"25000000"`.

## Next

<CardGroup cols={3}>
<Card title="Billing" icon="credit-card" href="./billing">
Credits, who pays, and the 402 fallback.
<Card title="API authentication" icon="key" href="../api/authentication">
Signing and session rules for raw verification calls.
</Card>
<Card title="Gate checkout" icon="door-open" href="./hosted-gate-checkout">
Charge visitors with USDC or card.
<Card title="MCP overview" icon="robot" href="../mcp/overview">
Connect the separate hosted MCP transport.
</Card>
<Card title="Agent delegation" icon="key" href="../agents/agent-delegation">
Spend caps for autonomous agents.
<Card title="Agent delegation" icon="shield" href="../agents/agent-delegation">
Authority scopes and autonomous spending caps.
</Card>
</CardGroup>
2 changes: 1 addition & 1 deletion docs/verifiers/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Verifier JSON Schemas

Request shapes for the public verifier catalog. Guides for people integrating NEUS live under **[Verification](../verification/verifiers)**.
Request shapes for the public verifier catalog. Guides for people integrating NEUS live under **[Verification](../verification/verifiers.mdx)**.

## Source of truth

Expand Down
25 changes: 17 additions & 8 deletions sdk/cli/neus.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { exec, spawnSync } from 'node:child_process';
import { spawn, spawnSync } from 'node:child_process';
import { createHash, randomBytes } from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
Expand Down Expand Up @@ -2098,13 +2098,22 @@ async function runAuthBrowser(options) {
logStep('next', 'wait', 'finish sign-in in the browser');
}

const openCommand = process.platform === 'win32'
? `cmd /c start "" "${authUrl.replace(/"/g, '\\"')}"`
: process.platform === 'darwin'
? `open "${authUrl.replace(/"/g, '\\"')}"`
: `xdg-open "${authUrl.replace(/"/g, '\\"')}"`;
exec(openCommand, { shell: true }, err => {
if (err && !options.json) {
// shell:false + argv array passes authUrl as a single argv element with no
// shell re-parse, so URL metacharacters (& | ; etc.) cannot be interpreted
// as shell control — eliminates the command-injection sink.
const opener =
process.platform === 'win32'
? { command: 'explorer', args: [authUrl] }
: process.platform === 'darwin'
? { command: 'open', args: [authUrl] }
: { command: 'xdg-open', args: [authUrl] };
const browser = spawn(opener.command, opener.args, {
shell: false,
stdio: 'ignore',
windowsHide: true
});
browser.on('error', () => {
if (!options.json) {
logStep('warn', 'browser', 'open the URL above manually');
}
});
Expand Down
Loading