Find best route
POST /public/v1/evm/{chain_id}/route
Compare shortlisted direct and one-intermediate-hop paths for an exact-input or exact-output swap. The router can split a fixed input across paths to return more output, or split a fixed output target to spend less input. A validated split can also fill an order when no single route can complete it.
This is a public endpoint. A Trading API key is optional; sending one raises your rate limit:
Authorization: Bearer <your_trading_api_key>
A key you send must be valid: an unknown key returns 401. Leave the header out if you don't have one.
Path parameters
chain_idRequest body
tokenIntokenOut, non-zero.tokenOuttradeTypeexact_in or exact_out. Inferred when omitted: amountIn alone ⇒ exact_in, amountOut alone ⇒ exact_out. Required if you send both amounts.amountInexact_inamountOutexact_outmaxRoutes1 to 4; 0 is treated as 1 and larger values as 4. 1 = single best route (no split); omitted = 4.poolAddresstokenIn/tokenOut; a success returns one direct route through it.Request
# Route (exact-in) - single & split, one endpoint
curl -X POST "https://api.metric.xyz/public/v1/evm/1/route" \
-H "Content-Type: application/json" \
-d '{
"tokenIn": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"tokenOut": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"tradeType": "exact_in",
"amountIn": "50000000000000000",
"maxRoutes": 4
}'Response
200 OK
{
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"tokenOut": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"tradeType": "exact_in",
"amountIn": "50000000000000000",
"amountOut": "136120897",
"effectivePriceX64": "50219747000",
"priceImpactBestRoute": "0.000082",
"candidatesConsidered": 8,
"routes": [
{
"tradeType": "exact_in",
"routeType": "direct",
"amountIn": "50000000000000000",
"amountOut": "136120897",
"effectivePriceX64": "50219747000",
"priceImpactE6": "82",
"legs": [
{
"tradeType": "exact_in",
"poolAddress": "0xF85AfbADeCC7F23Dd173ed706f07d9C7e2473e24",
"pair": "WETH/USDC",
"zeroForOne": true,
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"tokenOut": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"amountIn": "50000000000000000",
"amountOut": "136120897",
"effectivePriceX64": "50219747000",
"priceImpactE6": "82",
"priceLimitX64": "0"
}
]
}
]
}tokenIn / tokenOuttradeTypeamountInexact_in, the request; for exact_out, the computed required input.amountOutexact_in, the total computed output. For exact_out, the requested output.effectivePriceX64amountOut × 2^64 / amountIn, in raw token units (see below).priceImpactBestRoute"0.0135" = 1.35%).candidatesConsideredrouteseffectivePriceX64 is output per input, in the trade's direction (tokenOut per tokenIn), scaled by 2^64. It is not decimal-normalized, unlike bidAdj/askAdj. To get a human-readable price, compute effectivePriceX64 / 2^64 × 10^(tokenIn decimals − tokenOut decimals). In the example, 50219747000 / 2^64 ≈ 2.72e-9 USDC base units per wei, so × 10^(18 − 6) gives ≈ 2,722 USDC per WETH.
Response fields
Each routes[] entry
tradeTyperouteTypedirect or one_hop.amountIn / amountOuteffectivePriceX64priceImpactE6priceImpactE6 among this route's legs, E6 (10000 = 1%).legsEach leg
tradeTypepoolAddresspairzeroForOnetokenIn / tokenOutamountIn = leg 1 amountOut.amountIn / amountOuteffectivePriceX64priceImpactE6effectivePriceX64 for the average.priceLimitX640 when zeroForOne, 2^128−1 otherwise.Routing and splitting
These details are internal and not returned in the response.
- 1.Rank direct and one-hop paths using bid/ask depth. Use the same pool snapshot to price the finalists in the swap engine when it is available. Plans with snapshots for every leg take priority when they can fill the order. The router can fall back to depth estimates for older cache entries.
- 2.Use the best single quote in the group as the split reference. If no single can fill, use a full-size depth estimate from that group when one exists. A reference below the split threshold prevents splitting in that group.
- 3.Use marginal prices to plan a split within the configured limits and reprice its legs. For each simulated leg, the last traded bin and any output in a partially available bin must fit within the published depth.
- 4.Return a split when it improves the single quote. A split with snapshots for every leg can also fill an order when no full-size single-route reference exists.
Errors
400tokenIn == tokenOut, zero address, non-positive amount, missing amountIn/amountOut for the tradeType, or both amounts sent without a tradeType.401Invalid API key: an Authorization header was sent with an unknown key.404Unknown chainId: <id>: the chain is not served by the API.422no_route (no eligible direct/one-hop path), insufficient_liquidity (no candidate had enough depth), or token_disabled (tokenIn or tokenOut is disabled by Relatick).429Retry-After.500502503A 422 body carries a machine-readable code:
{
"code": "insufficient_liquidity",
"error": "no candidate route had enough depth to fill the requested amount"
}Last updated 29 days ago
Relatick