Skip to main content
GET
/
v2
/
earn
/
swap_quote
Python (SDK)
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>"
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}

Authorizations

x-api-key
string
header
required

Your Compass API Key. Get your key here.

Query Parameters

chain
enum<string>
default:base
required

Target blockchain network. The chain to use.

Available options:
base,
ethereum,
arbitrum,
hyperevm,
tempo,
bsc
token_in
string
default:WETH
required

Token to sell (input). A token symbol (e.g. 'WETH') or any token address.

token_out
string
default:USDC

Token to buy (output). A token symbol (e.g. 'USDC') or any token address.

sy_address
string | null

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.

amount_in
default:1
required

Human-readable amount of token_in to quote (token units, not wei).

Required range: x > 0
slippage
default:1.0

Maximum slippage tolerance as a percentage (e.g., 1 = 1%).

Required range: x >= 0

Response

Successful Response

Estimated output of a read-only swap quote.

amount_out
string
required

Estimated amount of token_out received, in human-readable units. Zero when no route / insufficient liquidity exists for the pair.

token_in
string
required

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.

token_out
string
required

The token address quoted as output — what amount_out is denominated in (the resolved token_out from the request).