LayelDocs

Layel documentation

Layel gives an agent the facts it needs before it sends a transaction: current gas, wallet balances, and a simulation of the exact transaction. Balances and the simulation are read at one pinned block.

Everything is plain HTTPS and JSON. Base URL: https://api.layel.xyz

ServiceEndpointPrice
Layel GasGET /v1/gasFree, Fair Use
Layel ScopePOST /v1/scope
Layel ProofGET /proofFree

Scope is paid per call with USDC on Base through the x402 protocol. There are no accounts and no API keys.

Base URL
https://api.layel.xyz
Machine-readable
# OpenAPI 3 spec
https://api.layel.xyz/openapi.json
# Guide written for agents
https://api.layel.xyz/llms.txt
# x402 discovery
https://api.layel.xyz/.well-known/x402

Quickstart

1. Read gas (free)

No setup. Run the request on the right. It returns the current fees on Base and a window of recent blocks.

2. Run Scope

Scope needs a wallet that holds a little USDC on Base. Install the x402 client and let it pay the 402 response for you:

npm i @x402/fetch @x402/evm viem

Use a separate wallet. Fund a dedicated wallet with a few cents of USDC. Keep the private key in an environment variable and never commit it.

A call that fails the consistency checksum is not charged. See Checksum and charging.

Gas, free
curl "https://api.layel.xyz/v1/gas?chain=base"
Scope, paid (Node)
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);
const pay = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
});

const res = await pay("https://api.layel.xyz/v1/scope", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    chain: "base",
    intent: "transfer",
    from: account.address,
    to: "0x000000000000000000000000000000000000dEaD",
    token: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    amount: "1000000",
  }),
});
console.log(await res.json());

Layel Gas Free

GET/v1/gas

Current gas price, EIP-1559 fees and a window of recent blocks, for one chain per request.

Query parameters

NameTypeDescription
chainstringbase (default), ethereum, arbitrum or polygon.
blocksintegerSize of the recent window, 1 to 200. Default 20.

Response fields

FieldDescription
gasPriceNode gas price, in wei (string).
baseFeePerGasBase fee of the latest block, in wei.
maxPriorityFeePerGasThe priority fee used for maxFeePerGas, in wei.
maxFeePerGasSuggested max fee in wei. It is 2 × baseFeePerGas + maxPriorityFeePerGas from maxFeeInputs. null if an input is missing.
maxFeeRulePlain-text rule used for this response.
maxFeeInputsThe inputs behind maxFeePerGas: the base fee used (next or current), the tip, and how many blocks the tip median covers.
gweiThe same values in gwei, as decimal strings.
recentThe last blocks blocks: base fee min, median and max, where the current base fee sits in that range (currentBaseFeePercentile), baseFeeRangePercent, trend and priority-fee percentiles. null if fee history is unavailable.

Fair Use: 30 requests per minute per IP. Each response shows what is left in RateLimit-Remaining and when the minute resets in RateLimit-Reset (seconds). Past the limit you get 429 with Retry-After.

Request
curl "https://api.layel.xyz/v1/gas?chain=base&blocks=20"
Response (shortened)
{
  "schema": "layel-gas/1",
  "chain": "base",
  "chainId": 8453,
  "block": { "number": 59486856, "ageSeconds": 0 },
  "gasPrice": "6000000",
  "baseFeePerGas": "5000000",
  "maxPriorityFeePerGas": "1000000",
  "maxFeePerGas": "11000000",
  "maxFeeRule": "2 x next base fee + median priority fee of the last 5 blocks",
  "maxFeeInputs": {
    "baseFeePerGas": "5000000",
    "baseFeeKind": "next",
    "maxPriorityFeePerGas": "1000000",
    "priorityFeeBlocks": 5
  },
  "gwei": { "gasPrice": "0.006", "maxFeePerGas": "0.011" },
  "recent": { "blocks": 20, "baseFeeTrend": "flat" }
}

Layel Scope

POST/v1/scope

One call reads the wallet's balances and destination at a single pinned block, simulates the transaction there, adds the pending nonce and the priority fee from the node's head, and returns anomalies in plain codes plus a signed receipt.

Body (JSON)

FieldDescription
intentrequiredtransfer, approve, swap or call.
fromrequiredWallet address. Balances are read and the simulation runs as this address.
chainbase (default), ethereum, arbitrum or polygon. Payment is always USDC on Base, whichever chain you read.
toRecipient (transfer) or target contract (call, swap).
tokenERC-20 address. Omit for the native token.
amountAtomic units as a decimal string: token units for token intents, wei for a native transfer or call.
spenderRequired for approve.
dataCalldata for call and swap. Required to simulate a swap. Not accepted for transfer or approve.

What comes back

  • data.simulation: status and, if it reverted, the decoded reason.
  • data.gas: the gas estimate and the same fee fields as Layel Gas (maxPriorityFeePerGas, maxFeePerGas, maxFeeRule, maxFeeInputs), plus feeHistory for the last 5 blocks.
  • data.native, data.token, data.nonce, data.destination: balances, nonce and whether the target is a contract.
  • anomalies: findings such as INSUFFICIENT_BALANCE or SIMULATION_REVERTED, each with a severity.
  • invariants and confidence: what was checked and how consistent the data is.
  • receipt: the signed receipt (below).

The result is advisory (advisoryOnly: true). A passed checksum means the data was consistent, not that the transaction will succeed. Read simulation and anomalies for that.

nonce.pendingPinned is false: the pending nonce comes from the node's head, not from the pinned block. gas.maxPriorityFeePinned is true when the priority fee is the median of the last 5 blocks at the pinned block, and false when fee history was unavailable and the fee is the node's suggestion. In both cases maxFeePerGas follows the same rule as Layel Gas.

Request body
{
  "chain": "base",
  "intent": "transfer",
  "from": "0xYourWallet...",
  "to": "0xRecipient...",
  "token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "amount": "5000000"
}
Response (shortened)
{
  "schema": "layel-scope/1",
  "chain": "base",
  "intent": "transfer",
  "advisoryOnly": true,
  "checksumPassed": true,
  "block": { "number": 59486856, "hash": "0x..." },
  "anomalies": [
    {
      "code": "INSUFFICIENT_BALANCE",
      "severity": "high",
      "message": "Token balance 1599100 is below the amount 5000000."
    }
  ],
  "data": {
    "simulation": { "status": "reverted" },
    "token": { "balance": "1599100", "decimals": 6 }
  },
  "receipt": { "alg": "EIP-712", "signer": "0x2c75..." }
}

Paying with x402

A request to /v1/scope without payment returns 402 Payment Required with the price and where to pay. An x402 client signs a USDC authorization, retries with the PAYMENT-SIGNATURE header, and gets the result. With @x402/fetch this happens inside fetch.

  • Version: x402 v2. Network: eip155:8453 (Base). Asset: USDC.
  • Price: US$0.01 (10000 atomic units of USDC) per call.
  • Verification and settlement go through the PayAI facilitator.
  • Settlement happens only after the checksum passes. If it does not pass, nothing is charged.

The settlement details come back in the PAYMENT-RESPONSE response header. Decode it with decodePaymentResponseHeader from @x402/fetch.

Without payment
curl -i -X POST https://api.layel.xyz/v1/scope \
  -H "Content-Type: application/json" \
  -d '{"intent":"transfer","from":"0x0000000000000000000000000000000000000001"}'

# HTTP/2 402
# the body lists the price, asset, network and payTo

Signed receipts

Every Scope response carries a receipt, an EIP-712 signature over what was delivered. It binds the request, the result, the pinned block, the payer and the amount, so you can prove later what Layel told your agent and when.

  • Schema: layel-receipt/1. Domain: Layel, version 1, chain 8453.
  • Signer: 0x2c7536E3605D9C16a7a3D7b1898e529396a65c23
  • The receipt includes its own types and domain, so you can verify it with any EIP-712 library.
  • requestHash is keccak256 of the canonical JSON of { endpoint, request }, where request is the body you sent.
  • resultHash is keccak256 of the canonical JSON of the response without its receipt field.
  • Canonical JSON: UTF-8, object keys sorted ascending, no whitespace, arrays in order.
  • amount is "0" when the checksum did not pass.

To verify, recompute both hashes and compare them with receipt.message, then check the signature and that the signer is the address above. Settlements are public on-chain, so you can also check the payment itself.

/proof serves the signer, the hashing rules and a sample receipt signed with the production key, so you can test your verifier before you pay for a call.

Verify a receipt (viem)
import { verifyTypedData, keccak256, toBytes } from "viem";

const canonical = (v) =>
  v === null || typeof v !== "object" ? JSON.stringify(v)
  : Array.isArray(v) ? "[" + v.map(canonical).join(",") + "]"
  : "{" + Object.keys(v).sort()
      .map((k) => JSON.stringify(k) + ":" + canonical(v[k])).join(",") + "}";

// `request` is the body you sent, `body` is the response.
const { receipt, ...result } = body;
const { signer, signature, domain, types, message } = receipt;

const hashesOk =
  keccak256(toBytes(canonical({ endpoint: message.endpoint, request }))) === message.requestHash &&
  keccak256(toBytes(canonical(result))) === message.resultHash;

const { EIP712Domain, ...rest } = types;
const msg = { ...message };
for (const k of ["blockNumber", "issuedAt", "confidence"]) msg[k] = BigInt(msg[k]);

const signatureOk = await verifyTypedData({
  address: signer, domain, types: rest,
  primaryType: "Receipt", message: msg, signature,
});
console.log(hashesOk, signatureOk,
  signer === "0x2c7536E3605D9C16a7a3D7b1898e529396a65c23");

Checksum and charging

Layel reads balances, allowance, the latest nonce and the simulation at one block, then re-reads to confirm the block did not change and the data agrees. This is the consistency checksum. It decides whether you pay.

OutcomeStatusCharged
Checksum passed200Yes, US$0.01
Checksum failed503 with Retry-AfterNo. The signed receipt in the body shows amount "0".
Upstream error before delivery502 or 503No

A 200 means the data is consistent. It does not mean your transaction will succeed.

Errors and limits

New to Layel? Layel gives AI agents pre-flight checks before they send a transaction: Gas is free and Scope costs US$0.01 per call. Start with the Quickstart or go to the home page.

Errors use one shape. retryable tells an agent whether trying again can help, and doc_url points to the row below that explains the error.

Every response, success or error, carries an X-Request-Id header. Quote it if you ask for help with a call.

StatusMeaning
400Invalid input, such as an unsupported chain or blocks outside 1 to 200.
402Payment required (Scope).
429Fair Use limit reached. Wait for Retry-After seconds.
502 / 503Data unavailable or checksum failed. Retry shortly. Not charged.

Each error has its own row in Error reasons.

Error body
{
  "error": {
    "reason": "rate_limited",
    "message": "Fair Use limit reached for Layel Gas (30 requests per minute per IP). Retry later.",
    "retryable": true,
    "doc_url": "https://layel.xyz/docs#err-rate_limited"
  }
}

Error reasons

Landed here from an error? Find your reason below. New to Layel? Start with the Quickstart.

Each error.reason has its own row. Open the link in doc_url to land on it.

ReasonWhat it meansWhat to do
invalid_input
400 / 413 · retry: no
A field is missing, malformed or out of range. The message names it. Body over 32768 bytes returns 413.Fix the field and send again. blocks is an integer from 1 to 200. The body must be a JSON object.
unsupported_chain
400 · retry: no
The chain value is not supported. The body lists them in supported.Use base, ethereum, arbitrum or polygon.
rate_limited
429 · retry: yes
Fair Use limit reached for your IP: 30 requests per minute for Gas, 20 for paid routes.Wait Retry-After seconds. RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset show your budget.
payment_already_used
409 · retry: no
This payment authorization was already used. Nothing was charged for this call.Sign a new payment with a fresh nonce and send it.
upstream_error
502 · retry: yes
A data provider failed or returned an invalid answer. For Scope you were not charged.Retry shortly. Gas sends Retry-After: 2.
service_unavailable
503 · retry: yes
The service, or the chain you asked for, is not configured right now.Retry later. Check another chain if only one fails.
temporarily_paused
503 · retry: yes
The service is temporarily paused.Wait Retry-After seconds.
billing_unavailable
503 · retry: yes
Payment options are not available, so Scope cannot quote a price.Retry later. Layel Gas keeps working.
proof_unavailable
502 · retry: yes
The proof document could not be produced.Retry shortly.
internal_error
500 · retry: yes
Something unexpected happened on our side.Retry later. If it repeats, quote the X-Request-Id header when you ask for help.
method_not_allowed
405 · retry: no
The route does not accept this HTTP method. Allow lists the right one.Use the method shown in Allow. Scope is POST.
not_found
404 · retry: no
The path does not exist.Check the path against the OpenAPI.

If a reason is not listed here, doc_url points to this section. Send the X-Request-Id with your question.

Payment messages (402)

A 402 body carries the quote in accepts and a short text in error. The text tells you what to change.

MessageWhat to do
Payment required
402
No payment was sent. This is the price quote: read accepts and send PAYMENT-SIGNATURE.
Invalid payment header
402
The header could not be decoded as base64 JSON. Build it again from accepts.
x402 v2 required
402
Send the PAYMENT-SIGNATURE header with an x402 v2 payload.
Unsupported network
402
The payment names a network that is not in accepts. Pay on Base.
Payment does not match requirements
402
Amount, asset or recipient differs from accepts. Copy them exactly.
Payment invalid: <reason>
402
The facilitator rejected the signature or authorization. The reason is appended. Sign again.
Settlement failed: <reason>
402
The payment verified but did not settle, and no result was delivered. Retry with a new payment.

A checksum failure is a 503 with the signed receipt in the body and no charge. See Checksum and charging.

Anomaly codes

Layel Scope lists findings in anomalies. Each has a code, a severity (high, medium or info) and a message. They are facts at the pinned block. The revert reason itself stays in data.simulation.

CodeWhat it means
INSUFFICIENT_BALANCE
high
The native or token balance is below the amount in the request.
INSUFFICIENT_BALANCE_AFTER_GAS
high
The native balance covers the amount but not the estimated gas cost.
LOW_GAS_BALANCE
high
The native balance is below the estimated gas cost.
INSUFFICIENT_ALLOWANCE
high
For a swap, the allowance for the spender is below the amount.
SIMULATION_REVERTED
high
The simulated transaction reverted at the pinned block. See data.simulation.revert.
TOKEN_RETURNED_FALSE
high
The token call returned false: the token reports the operation as failed.
STALE_BLOCK
high / medium
The block is old for this chain, so the node may be lagging.
PENDING_TRANSACTIONS
medium
The sender has pending transactions, so the next nonce may differ.
UNLIMITED_ALLOWANCE
medium
The existing allowance for this spender is the maximum uint256.
UNLIMITED_APPROVAL_REQUESTED
medium
The approval in the request is the maximum uint256.
SIMULATION_UNAVAILABLE
medium
The provider could not complete the simulation, so success is unverified.
TARGET_HAS_NO_CODE
medium
The calldata goes to an address with no contract code at this block; it would act as a plain value transfer.
SPENDER_HAS_NO_CODE
medium
The spender has no contract code at this block.
SIMULATION_SKIPPED
info
The transaction was not simulated, so success is unverified. See data.simulation.reason.
ALLOWANCE_ALREADY_SUFFICIENT
info
For an approval, the existing allowance already covers the amount.
RECIPIENT_IS_CONTRACT
info
For a transfer, the recipient is a contract at this block.
BASE_FEE_RISING
info
The next base fee is more than 5% above the current one.

MCP server

Agents that speak the Model Context Protocol can use Layel as a tool server. It is the same service behind the same rules.

ToolDoesPrice
layel_gasSame as GET /v1/gas.Free
layel_scopeSame as POST /v1/scope.US$0.01

Transport: Streamable HTTP, JSON responses, stateless. When layel_scope needs payment, the tool returns the x402 payment requirements; the client retries with the payment in _meta.

List the tools
curl -X POST https://api.layel.xyz/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

Chains and versions

Supported chains: Base, Ethereum, Arbitrum One and Polygon. Solana is on the roadmap.

Every response names its schema (layel-gas/1, layel-scope/1, layel-receipt/1). Fields can be added inside a version, so ignore fields you do not know. A change that removes or reshapes a field gets a new version.

Questions or something not working? Check /proof and the guide for agents.

Changelog

Changes inside a version are additive: new fields and headers appear, nothing is removed or renamed. Anything that removes or reshapes a field gets a new version (layel-gas/2, for example).

November 2026

  • Gas: RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset headers show your Fair Use budget before you hit the limit.
  • All endpoints: every response carries an X-Request-Id header. Every error body carries error.doc_url.
  • Proof: /proof now has a docs field that links to the receipt documentation.
  • Gas: maxFeeInputs shows the inputs behind maxFeePerGas, so you can recompute it.
  • Gas: blocks parameter and a recent window with base fee range, percentile and priority-fee percentiles.
  • MCP: the layel_gas tool no longer declares an empty required list.
  • Docs: this documentation is published.

Launch

  • Layel Gas, Layel Scope and Layel Proof, with signed layel-receipt/1 receipts and an MCP server.