Swaps
Create a Swap

Create a swap

Swaps one token in your API accounts for another, at the price of a quote from Quote a swap. The swap is instant: it is complete when you get the response.

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

How it works

A swap changes two API account balances, using the amounts from the quote:

BalanceChange
API account for fromTokenGoes down by totalDebit: amount plus fee
API account for toTokenGoes up by toAmount

Your network liquidity on the swap's network changes the same way: less fromToken, more toToken.

Before the swap runs, Knit checks:

  • the quote has not expired and has not been used,
  • the market price has not moved against the quote since it was made,
  • your fromToken API account and your network liquidity cover totalDebit.

If any check fails, Knit refuses the swap and nothing moves. See Errors.

Body

quoteIdstringrequired

The id from Quote a swap. Each quote can make one swap. A swap that Knit refuses does not use up the quote.

merchantReferencestringrequired

Your own reference for this swap. It must be unique among the swaps of your business. Maximum 255 characters. It lets you retry without swapping twice.

Sending a request again

If you are not sure whether a swap went through, for example after a timeout, send the same request again: the same quoteId and the same merchantReference. If Knit already made the swap, you get 200 with the same swap in data as the first time, and nothing moves twice. This works even after the quote's expiresAt. If Knit did not make the swap, the request is handled as new.

You can also look the reference up with List swaps and ?merchantReference=.

A merchantReference that your business used for a different swap gets DUPLICATE_MERCHANT_REFERENCE, and nothing moves. A quoteId that already made a swap under a different merchantReference gets QUOTE_EXPIRED. When a quote expired or the price moved, no swap was made, so you can use the same reference with the new quote.

Request

cURL
curl -X POST "https://api-prod.useknit.io/api/v1/swaps" \
  -H "Authorization: Bearer $KNIT_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "quoteId": "5b1e0c7a-8f43-4d2e-9b61-2f0d3c4a7e91",
    "merchantReference": "swap-001"
  }'

Response

Returns 201 for a new swap. When you send a swap you already made again, it returns 200, the message Swap retrieved successfully and the same data.

201 Created
{
  "statusCode": 201,
  "message": "Swap created successfully",
  "data": {
    "id": "e2a4f6b8-1c3d-4e5f-8a9b-0c1d2e3f4a5b",
    "merchantReference": "swap-001",
    "quoteId": "5b1e0c7a-8f43-4d2e-9b61-2f0d3c4a7e91",
    "fromToken": "USDT",
    "toToken": "ETH",
    "network": "ETHEREUM_MAINNET",
    "amount": "1000",
    "toAmount": "0.33195",
    "rate": "0.00033195",
    "fee": "8.2",
    "feesBreakdown": [
      { "type": "NETWORK", "amount": "3.2" },
      { "type": "KNIT", "amount": "5" }
    ],
    "totalDebit": "1008.2",
    "fromBalanceAfter": "3991.8",
    "toBalanceAfter": "1.33195",
    "status": "SUCCESSFUL",
    "createdAt": "2026-11-24T10:15:12.000000Z"
  },
  "success": true
}

amount, toAmount, rate, fee, feesBreakdown and totalDebit are the ones from the quote.

quoteIdstring

The quote this swap used.

fromBalanceAfterstring

Your API account balance for fromToken after the swap.

toBalanceAfterstring

Your API account balance for toToken after the swap.

statusstring

Always SUCCESSFUL. A swap that Knit refuses is not created.

Knit also sends the SWAP_SUCCESSFUL webhook for each new swap.

Errors

Refusals carry a code. The message is for people and can change, so branch on code. Nothing moves when a swap is refused.

400 — quote expired
{
  "statusCode": 400,
  "message": "The quote has expired. Request a new quote.",
  "data": null,
  "success": false,
  "code": "QUOTE_EXPIRED"
}
StatuscodeWhat it meansWhat to do
400QUOTE_EXPIREDThe quote passed its expiresAt before Knit received the request, or it already made a swap under a different merchantReferenceGet a new quote and create the swap with it
400QUOTE_NOT_FOUNDNo quote of your business has this quoteIdCheck the quoteId, or get a new quote
400DUPLICATE_MERCHANT_REFERENCEYour business already used this merchantReference for a different swapUse a new reference for a new swap
400INSUFFICIENT_BALANCEYour API account for fromToken has less than totalDebitFund the account, or swap less
400INSUFFICIENT_NETWORK_LIQUIDITYYour network liquidity for fromToken on network does not cover the swapSwap less, or bridge liquidity to network
400PAIR_NOT_SUPPORTEDKnit no longer offers this pair on this networkUse a pair Knit offers
400AMOUNT_BELOW_MINIMUMThe amount is below the smallest swap for this pairGet a quote for more
400AMOUNT_ABOVE_MAXIMUMThe amount is above the largest swap for this pairGet a quote for less, or split the amount
409PRICE_MOVEDThe market price moved against the quote after it was madeGet a new quote and decide again
503PRICE_UNAVAILABLEKnit cannot get a reliable market price for this pair right nowTry again in a few minutes with a new quote
503PRICE_CHECK_FAILEDThe price did not pass Knit's check against the market priceTry again in a few minutes with a new quote
503CAPACITY_REACHEDKnit has paused this kind of swap for nowTry again later with a new quote

Other responses:

StatusCause
400A field failed validation, for example a missing merchantReference or a quoteId that is not a UUID. 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. Nothing moved, so try again later

QUOTE_EXPIRED and PRICE_MOVED protect you from a price you did not agree to. Get a new quote and check it before you create the swap again.