from compass_api_sdk import CompassAPI, models
with CompassAPI(
api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
res = compass_api.earn.earn_swap_quote(chain=models.V2EarnSwapQuoteChain.BASE, token_in="WETH", amount_in="1", token_out="USDC", slippage="1.0")
# Handle response
print(res)import { CompassApiSDK } from "@compass-labs/api-sdk";
const compassApiSDK = new CompassApiSDK({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await compassApiSDK.earn.earnSwapQuote({
chain: "base",
tokenIn: "WETH",
tokenOut: "USDC",
amountIn: "1",
slippage: "1.0",
});
console.log(result);
}
run();curl --request GET \
--url https://api.compasslabs.ai/v2/earn/swap_quote \
--header 'x-api-key: <api-key>'const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.compasslabs.ai/v2/earn/swap_quote', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.compasslabs.ai/v2/earn/swap_quote",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.compasslabs.ai/v2/earn/swap_quote"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.compasslabs.ai/v2/earn/swap_quote")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.compasslabs.ai/v2/earn/swap_quote")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"amount_out": "<string>",
"token_in": "<string>",
"token_out": "<string>",
"swap_provider": "market"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Quote a swap
Estimate the output of a swap without building a transaction.
Returns the expected amount of token_out received for selling amount_in
of token_in. On chains with a market route this is the market rate; on
HyperEVM, where swaps are firm-priced, it is an indicative price from the
firm provider’s live levels (swap_provider tells you which). This is
read-only: it does not build a transaction, require an account, or check
balances.
Use it to gauge exit liquidity and price impact for a token before entering a position — for example, to warn when a market’s underlying asset cannot be swapped back to a stablecoin without large slippage.
from compass_api_sdk import CompassAPI, models
with CompassAPI(
api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
res = compass_api.earn.earn_swap_quote(chain=models.V2EarnSwapQuoteChain.BASE, token_in="WETH", amount_in="1", token_out="USDC", slippage="1.0")
# Handle response
print(res)import { CompassApiSDK } from "@compass-labs/api-sdk";
const compassApiSDK = new CompassApiSDK({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await compassApiSDK.earn.earnSwapQuote({
chain: "base",
tokenIn: "WETH",
tokenOut: "USDC",
amountIn: "1",
slippage: "1.0",
});
console.log(result);
}
run();curl --request GET \
--url https://api.compasslabs.ai/v2/earn/swap_quote \
--header 'x-api-key: <api-key>'const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.compasslabs.ai/v2/earn/swap_quote', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.compasslabs.ai/v2/earn/swap_quote",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.compasslabs.ai/v2/earn/swap_quote"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.compasslabs.ai/v2/earn/swap_quote")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.compasslabs.ai/v2/earn/swap_quote")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"amount_out": "<string>",
"token_in": "<string>",
"token_out": "<string>",
"swap_provider": "market"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Query Parameters
Target blockchain network.
arbitrum, base, bsc, ethereum, hyperevm, tempo Token to sell (input). A token symbol (e.g. 'WETH') or any token address.
Token to buy (output). A token symbol (e.g. 'USDC') or any token address.
Optional Pendle SY (Standardized Yield) address. When provided, token_in is overridden with the token the PT actually redeems into on withdrawal (the SY asset if it is a valid token-out, else the SY yield token) — use this to gauge a Pendle position's real exit liquidity rather than the reported underlying.
Human-readable amount of token_in to quote (token units, not wei).
x > 0Maximum slippage tolerance as a percentage (e.g., 1 = 1%).
x >= 0Response
Successful Response
Estimated output of a read-only swap quote.
Estimated amount of token_out received, in human-readable units. On the market route, zero when no route / insufficient liquidity exists for the pair (a definitive answer). On the firm route (HyperEVM) a missing or short price book is a 409 instead, never a zero: unlike a missing route it is transient, so retry.
The token address actually quoted as input. Usually the requested token_in; for Pendle (when sy_address is supplied) it is the resolved redeem token, which callers should use to value the input.
The token address quoted as output — what amount_out is denominated in (the resolved token_out from the request).
Which route priced the estimate. 'market': the market aggregator's price-only quote. 'firm': an INDICATIVE price from the firm provider's live levels (HyperEVM), computed without spending a quote; the executable build fetches the firm quote itself. When those levels cannot price amount_in the endpoint answers 409 rather than a zero amount_out.
market, firm Was this page helpful?