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
| Service | Endpoint | Price |
|---|---|---|
| Layel Gas | GET /v1/gas | Free, Fair Use |
| Layel Scope | POST /v1/scope | US$0.01 per call |
| Layel Proof | GET /proof | Free |
Scope is paid per call with USDC on Base through the x402 protocol. There are no accounts and no API keys.
https://api.layel.xyz
# 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
A call that fails the consistency checksum is not charged. See Checksum and charging.
curl "https://api.layel.xyz/v1/gas?chain=base"
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
Current gas price, EIP-1559 fees and a window of recent blocks, for one chain per request.
Query parameters
| Name | Type | Description |
|---|---|---|
chain | string | base (default), ethereum, arbitrum or polygon. |
blocks | integer | Size of the recent window, 1 to 200. Default 20. |
Response fields
| Field | Description |
|---|---|
gasPrice | Node gas price, in wei (string). |
baseFeePerGas | Base fee of the latest block, in wei. |
maxPriorityFeePerGas | The priority fee used for maxFeePerGas, in wei. |
maxFeePerGas | Suggested max fee in wei. It is 2 × baseFeePerGas + maxPriorityFeePerGas from maxFeeInputs. null if an input is missing. |
maxFeeRule | Plain-text rule used for this response. |
maxFeeInputs | The inputs behind maxFeePerGas: the base fee used (next or current), the tip, and how many blocks the tip median covers. |
gwei | The same values in gwei, as decimal strings. |
recent | The 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.
curl "https://api.layel.xyz/v1/gas?chain=base&blocks=20"
{
"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 US$0.01
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)
| Field | Description |
|---|---|
intentrequired | transfer, approve, swap or call. |
fromrequired | Wallet address. Balances are read and the simulation runs as this address. |
chain | base (default), ethereum, arbitrum or polygon. Payment is always USDC on Base, whichever chain you read. |
to | Recipient (transfer) or target contract (call, swap). |
token | ERC-20 address. Omit for the native token. |
amount | Atomic units as a decimal string: token units for token intents, wei for a native transfer or call. |
spender | Required for approve. |
data | Calldata for call and swap. Required to simulate a swap. Not accepted for transfer or approve. |
What comes back
data.simulation:statusand, if it reverted, the decoded reason.data.gas: the gas estimate and the same fee fields as Layel Gas (maxPriorityFeePerGas,maxFeePerGas,maxFeeRule,maxFeeInputs), plusfeeHistoryfor the last 5 blocks.data.native,data.token,data.nonce,data.destination: balances, nonce and whether the target is a contract.anomalies: findings such asINSUFFICIENT_BALANCEorSIMULATION_REVERTED, each with a severity.invariantsandconfidence: 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.
{
"chain": "base",
"intent": "transfer",
"from": "0xYourWallet...",
"to": "0xRecipient...",
"token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"amount": "5000000"
}{
"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 (
10000atomic 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.
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 payToSigned 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, version1, chain8453. - Signer:
0x2c7536E3605D9C16a7a3D7b1898e529396a65c23 - The receipt includes its own
typesanddomain, so you can verify it with any EIP-712 library. requestHashiskeccak256of the canonical JSON of{ endpoint, request }, whererequestis the body you sent.resultHashiskeccak256of the canonical JSON of the response without itsreceiptfield.- Canonical JSON: UTF-8, object keys sorted ascending, no whitespace, arrays in order.
amountis"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.
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.
| Outcome | Status | Charged |
|---|---|---|
| Checksum passed | 200 | Yes, US$0.01 |
| Checksum failed | 503 with Retry-After | No. The signed receipt in the body shows amount "0". |
| Upstream error before delivery | 502 or 503 | No |
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.
| Status | Meaning |
|---|---|
400 | Invalid input, such as an unsupported chain or blocks outside 1 to 200. |
402 | Payment required (Scope). |
429 | Fair Use limit reached. Wait for Retry-After seconds. |
502 / 503 | Data unavailable or checksum failed. Retry shortly. Not charged. |
Each error has its own row in Error reasons.
{
"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.
| Reason | What it means | What to do |
|---|---|---|
invalid_input | 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 | The chain value is not supported. The body lists them in supported. | Use base, ethereum, arbitrum or polygon. |
rate_limited | 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 | 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 | A data provider failed or returned an invalid answer. For Scope you were not charged. | Retry shortly. Gas sends Retry-After: 2. |
service_unavailable | The service, or the chain you asked for, is not configured right now. | Retry later. Check another chain if only one fails. |
temporarily_paused | The service is temporarily paused. | Wait Retry-After seconds. |
billing_unavailable | Payment options are not available, so Scope cannot quote a price. | Retry later. Layel Gas keeps working. |
proof_unavailable | The proof document could not be produced. | Retry shortly. |
internal_error | 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 | The route does not accept this HTTP method. Allow lists the right one. | Use the method shown in Allow. Scope is POST. |
not_found | 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.
| Message | What to do |
|---|---|
| Payment required | No payment was sent. This is the price quote: read accepts and send PAYMENT-SIGNATURE. |
| Invalid payment header | The header could not be decoded as base64 JSON. Build it again from accepts. |
| x402 v2 required | Send the PAYMENT-SIGNATURE header with an x402 v2 payload. |
| Unsupported network | The payment names a network that is not in accepts. Pay on Base. |
| Payment does not match requirements | Amount, asset or recipient differs from accepts. Copy them exactly. |
| Payment invalid: <reason> | The facilitator rejected the signature or authorization. The reason is appended. Sign again. |
| Settlement failed: <reason> | 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.
| Code | What it means |
|---|---|
INSUFFICIENT_BALANCE | The native or token balance is below the amount in the request. |
INSUFFICIENT_BALANCE_AFTER_GAS | The native balance covers the amount but not the estimated gas cost. |
LOW_GAS_BALANCE | The native balance is below the estimated gas cost. |
INSUFFICIENT_ALLOWANCE | For a swap, the allowance for the spender is below the amount. |
SIMULATION_REVERTED | The simulated transaction reverted at the pinned block. See data.simulation.revert. |
TOKEN_RETURNED_FALSE | The token call returned false: the token reports the operation as failed. |
STALE_BLOCK | The block is old for this chain, so the node may be lagging. |
PENDING_TRANSACTIONS | The sender has pending transactions, so the next nonce may differ. |
UNLIMITED_ALLOWANCE | The existing allowance for this spender is the maximum uint256. |
UNLIMITED_APPROVAL_REQUESTED | The approval in the request is the maximum uint256. |
SIMULATION_UNAVAILABLE | The provider could not complete the simulation, so success is unverified. |
TARGET_HAS_NO_CODE | 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 | The spender has no contract code at this block. |
SIMULATION_SKIPPED | The transaction was not simulated, so success is unverified. See data.simulation.reason. |
ALLOWANCE_ALREADY_SUFFICIENT | For an approval, the existing allowance already covers the amount. |
RECIPIENT_IS_CONTRACT | For a transfer, the recipient is a contract at this block. |
BASE_FEE_RISING | 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.
| Tool | Does | Price |
|---|---|---|
layel_gas | Same as GET /v1/gas. | Free |
layel_scope | Same 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.
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-RemainingandRateLimit-Resetheaders show your Fair Use budget before you hit the limit. - All endpoints: every response carries an
X-Request-Idheader. Every error body carrieserror.doc_url. - Proof:
/proofnow has adocsfield that links to the receipt documentation. - Gas:
maxFeeInputsshows the inputs behindmaxFeePerGas, so you can recompute it. - Gas:
blocksparameter and arecentwindow with base fee range, percentile and priority-fee percentiles. - MCP: the
layel_gastool no longer declares an emptyrequiredlist. - Docs: this documentation is published.
Launch
- Layel Gas, Layel Scope and Layel Proof, with signed
layel-receipt/1receipts and an MCP server.