Skip to main content
Sepolia Testnet Only — All data is from Ethereum Sepolia. Token balances and positions have no real-world value. Write payments use Sepolia USDC.

What is x402?

The x402 protocol enables HTTP-native micropayments using the 402 Payment Required status code. When you call a paid endpoint without payment, the server returns a 402 response with payment requirements. Your client pays the specified amount (onchain USDC transfer), attaches the payment proof to a retry, and the server fulfills the request. The Nile Markets x402 API splits access into two tiers:
  • Read endpoints (GET) — Free, no payment required
  • Write endpoints (POST) — $0.01 USDC per request via x402
Base URL: https://x402.nilemarkets.com

Free Endpoints (14 GET)

Pool and Protocol

MethodPathDescriptionQuery Params
GET/api/x402/pool/statePool metrics: total assets, shares, share price, utilizationnetwork?
GET/api/x402/pool/transactionsHistorical vault deposits and withdrawalsfirst?, skip?, network?
GET/api/x402/protocol/modeOperating mode: NORMAL, DEGRADED, REDUCE_ONLY, or PAUSEDnetwork?
GET/api/x402/stats/dailyDaily volume, fees, position opens/closes, pool PnLdays?, network?

Positions

MethodPathDescriptionQuery Params
GET/api/x402/positionsPositions for an accountaccount (required), status?, first?, skip?, network?
GET/api/x402/positions/searchSearch all positions with filtersside?, tenor?, status?, minNotional?, first?, skip?, network?
GET/api/x402/position/[id]Single position with real-time PnL

Oracle and Pricing

MethodPathDescriptionQuery Params
GET/api/x402/oracle/stateFull oracle state: spot, all forward prices, validitypairId?, network?
GET/api/x402/oracle/forwardForward price for a specific tenortenor (required), pairId?, network?

Accounts and Fees

MethodPathDescriptionQuery Params
GET/api/x402/account/[address]Account margin: collateral, locked, available, position count
GET/api/x402/feesFee event breakdown (trading, liquidation, termination, oracle)first?, skip?, network?

Token and Simulation

MethodPathDescriptionQuery Params
GET/api/x402/token/balanceERC-20 token balance for an addressaddress (required), token?, network?
GET/api/x402/token/allowanceERC-20 allowance for an owner/spender pairowner (required), spender (required), token?, network?
GET/api/x402/simulate/openPreview margin, fee, and entry strikeside, tenor, notional (all required), margin?, from?, network?
Each POST request costs $0.01 USDC on Sepolia, paid via the x402 protocol. The payment is a separate onchain USDC transfer to the configured payee address, verified by an x402 facilitator before the request is fulfilled.

Trading

MethodPathDescriptionBody Fields
POST/api/x402/position/openCalldata to open a new FX forward positionside, tenor, notional, margin, pairId?, from?
POST/api/x402/position/closeCalldata to close a position via early terminationpositionId, from?

Margin

MethodPathDescriptionBody Fields
POST/api/x402/margin/depositCalldata to deposit USDC as margin collateralamount, from?
POST/api/x402/margin/withdrawCalldata to withdraw available USDC marginamount, from?

Vault (Liquidity Providers)

MethodPathDescriptionBody Fields
POST/api/x402/vault/depositCalldata to deposit USDC into the pool vaultamount, receiver, from?
POST/api/x402/vault/withdrawCalldata to withdraw USDC from the pool vaultamount, receiver, owner, from?

Token Approval and Testnet

MethodPathDescriptionBody Fields
POST/api/x402/token/approveCalldata to approve a Nile contract to spend tokensspender, amount, token?, from?
POST/api/x402/token/mintCalldata to mint test tokens (testnet only)to, amount, from?
All amounts are strings in USDC smallest unit (6 decimals). "1000000000" = 1,000 USDC.

Response Format

Every response uses a standard JSON envelope:
{
  "success": true,
  "data": { },
  "protocol": { "name": "Nile Markets", "version": "0.3.0" },
  "network": "sepolia",
  "timestamp": "2025-06-15T12:00:00.000Z",
  "blockNumber": "12345678",
  "source": "rpc+subgraph"
}
FieldTypeDescription
successbooleantrue for 2xx responses, false for errors
dataobject?Endpoint-specific payload (omitted on errors)
errorstring?Error message (omitted on success)
protocol{ name, version }Protocol identity and API version
networkstringTarget network ("sepolia")
timestampstringISO 8601 response timestamp
blockNumberstring?Last indexed block (subgraph-sourced responses)
sourcestring?Data source: "rpc", "subgraph", or "rpc+subgraph"
Write endpoints return TransactionCalldata in the data field, identical to the MCP server format.

Examples

Free Read — Pool State

curl -s https://x402.nilemarkets.com/api/x402/pool/state | jq
{
  "success": true,
  "data": {
    "totalAssets": "50000000000",
    "totalShares": "49500000000",
    "sharePrice": "1010101010101010101",
    "utilization": "3200",
    "longExposure": "10000000000",
    "shortExposure": "6000000000"
  },
  "protocol": { "name": "Nile Markets", "version": "0.3.0" },
  "network": "sepolia",
  "timestamp": "2025-06-15T12:00:00.000Z",
  "source": "rpc+subgraph"
}

Free Read — Forward Price

curl -s "https://x402.nilemarkets.com/api/x402/oracle/forward?tenor=1M" | jq
Without payment, the server returns 402 Payment Required with x402 payment requirements:
curl -s -X POST https://x402.nilemarkets.com/api/x402/position/open \
  -H "Content-Type: application/json" \
  -d '{
    "side": "LONG",
    "tenor": "1M",
    "notional": "10000000000",
    "margin": "20000000"
  }'
{
  "error": "X-PAYMENT header is required",
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:11155111",
    "maxAmountRequired": "10000",
    "resource": "https://x402.nilemarkets.com/api/x402/position/open",
    "description": "Open a new FX forward position",
    "mimeType": "application/json"
  }]
}
To complete the payment, use an x402-compatible client library that handles the 402 → pay → retry flow automatically. See x402.org for client SDKs in TypeScript, Python, and Go.

x402 Payment Flow

1

Initial request

Your client sends a POST to a paid endpoint without payment headers.
2

402 response

The server returns HTTP 402 with accepts containing the payment scheme, amount ($0.01 USDC), network, and payee address.
3

Onchain payment

Your client transfers the specified USDC amount to the payee address on Sepolia and obtains a payment proof.
4

Retry with proof

Your client retries the original request with the X-PAYMENT header containing the payment proof.
5

Fulfillment

The server verifies the payment via the x402 facilitator and returns the requested data (unsigned transaction calldata for write endpoints).
x402 client libraries (available at x402.org) handle steps 2 through 4 automatically.

Rate Limits

TierLimitEnforcement
Free endpoints (GET)100 req/min per IPHTTP 429 with Retry-After
Paid endpoints (POST)No rate limitPayment itself throttles abuse

MCP vs x402

The MCP server and x402 API expose the same 22 operations with identical data. Choose based on your client:
MCP Serverx402 API
TransportStreamable HTTP (MCP protocol)Standard REST (HTTP)
ClientAI agents with MCP supportAny HTTP client (curl, fetch, SDKs)
AuthNoneFree reads; $0.01 USDC per write
Response formatMCP content blocksJSON envelope with success, timestamp
Best forClaude, ChatGPT, Cursor, VS CodeProgrammatic integrations, scripts, bots