Swaps
Quote a Swap

Quote a swap

A swap exchanges one token in your API accounts for another, for example USDT for ETH. It takes two requests:

  1. Quote. Ask for a price. Knit answers with exactly what you pay, what you get and the fees, and holds that price until expiresAt.
  2. Create. Create the swap with the quote's id before it expires. The swap happens at the quoted price, or not at all.

Nothing moves and nothing is held when you ask for a quote.

POST
https://api-prod.useknit.io/api/v1/swaps/quote
Scopeswaps:writeAuthBearer token

Before you call

  • You need an API account for both tokens. Create one for any token you do not have an account for yet.
  • Knit chooses the pairs it offers, and on which networks. These include USDT and USDC, and ETH with USDT or USDC on ETHEREUM_MAINNET, as Knit switches each pair on. A pair that is not offered gets PAIR_NOT_SUPPORTED.

Body

fromTokenstringrequired

The token you pay with, for example USDT.

toTokenstringrequired

The token you get, for example ETH. It must not be the same as fromToken.

networkstringrequired

The network the swap happens on, for example ETHEREUM_MAINNET. Both tokens are on this network.

amountnumber | stringrequired

How much fromToken to swap, in token units, with at most 18 decimal places. The fees are added on top. Send it as a string to keep every decimal.

Request

cURL
curl -X POST "https://api-prod.useknit.io/api/v1/swaps/quote" \
  -H "Authorization: Bearer $KNIT_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fromToken": "USDT",
    "toToken": "ETH",
    "network": "ETHEREUM_MAINNET",
    "amount": "1000"
  }'

Response

201 Created
{
  "statusCode": 201,
  "message": "Swap quote created successfully",
  "data": {
    "id": "5b1e0c7a-8f43-4d2e-9b61-2f0d3c4a7e91",
    "fromToken": "USDT",
    "toToken": "ETH",
    "network": "ETHEREUM_MAINNET",
    "amount": "1000",
    "toAmount": "0.33195",
    "rate": "0.00033195",
    "marketRate": "0.0003324",
    "fee": "8.2",
    "feesBreakdown": [
      { "type": "NETWORK", "amount": "3.2" },
      { "type": "KNIT", "amount": "5" }
    ],
    "totalDebit": "1008.2",
    "expiresAt": "2026-11-24T10:15:30Z"
  },
  "success": true
}

All amounts are strings in token units. Use them as they are: do not recalculate them.

idstring

The quote. Send it as quoteId to Create a swap.

amountstring

How much fromToken is swapped, without fees.

toAmountstring

How much toToken you get. This is what is added to your toToken API account.

ratestring

What you get for 1 fromToken, in toToken. It already includes the cost of making the exchange. The fees are charged on top of amount, not taken from toAmount.

marketRatestring

The market price of 1 fromToken in toToken when Knit made the quote. It is shown for comparison only: the swap uses rate.

feestring

The total fees, in fromToken. 0 when no fee applies.

feesBreakdownarray

The parts of fee. Each item has a type and an amount in fromToken, and the amounts add up to fee. NETWORK is the network cost of making the swap. KNIT is Knit's fee.

totalDebitstring

amount plus fee: what leaves your fromToken API account.

expiresAtstring

When the price stops being valid. Create the swap before this time.

When a quote expires

A quote is valid for a short time, usually less than a minute. Read expiresAt from each quote rather than assuming a fixed time, and create the swap straight after you decide to accept the price.

If the quote has expired when Knit receives your create request, Knit refuses with QUOTE_EXPIRED and nothing moves. Ask for a new quote, check the new price, and create the swap with the new id. Prices move, so the new quote can be better or worse than the old one: do not accept it automatically unless your own rules allow that.

A quote does not reserve your balance. Knit checks your balances when you create the swap.

Errors

Refusals carry a code that tells you what happened. The message is for people and can change, so branch on code.

503 — price unavailable
{
  "statusCode": 503,
  "message": "Swap prices are unavailable right now. Try again shortly.",
  "data": null,
  "success": false,
  "code": "PRICE_UNAVAILABLE"
}
StatuscodeWhat it meansWhat to do
400PAIR_NOT_SUPPORTEDKnit does not offer this pair on this networkUse a pair Knit offers
400AMOUNT_BELOW_MINIMUMamount is below the smallest swap for this pairSwap more
400AMOUNT_ABOVE_MAXIMUMamount is above the largest swap for this pairSwap less, or split the amount
503PRICE_UNAVAILABLEKnit cannot get a reliable market price for this pair right nowTry again in a few minutes
503PRICE_CHECK_FAILEDThe price did not pass Knit's check against the market priceTry again in a few minutes
503CAPACITY_REACHEDKnit has paused this kind of swap for nowTry again later

Other responses:

StatusCause
400A field failed validation, for example a missing amount, more than 18 decimal places, or the same token twice. The body has an errors entry for the field and no code
401Missing or invalid token, IP not allow-listed, or missing swaps:write
403API Services are not enabled for your business
503Swaps are temporarily unavailable. Please try again later. Knit has paused swaps. The body has no code