Exact Buy (Exact Out)
Exact Buy (Exact Out)
The Swap API supports exact out swaps via the buyAmount parameter. Instead of specifying how much to sell, you specify the exact output the swap must deliver — and 0x sizes and routes the input to guarantee it.
This unlocks use cases like:
- Merchant checkout where the seller receives exactly the invoiced amount
- Invoicing and bill pay with no rounding or shortfall
- Fixed-amount payouts to contractors or sellers regardless of which asset the treasury holds
- Subscriptions that charge a fixed price each cycle while users hold any asset
Exact out is supported on the Swap API via the buyAmount parameter.
How it works
Send buyAmount on a price or quote request in place of sellAmount. The response sizes the input and returns maxSellAmount — the ceiling the taker needs to cover in balance and allowance.
The swap acquires at least buyAmount and converts any surplus back to the sell token, returning it to the taker in the same transaction. The recipient receives exactly buyAmount.
If recipient is omitted, it defaults to the taker address. Combine buyAmount with recipient to deliver an exact amount directly to a merchant or third-party address — in a single transaction. See Swap and Send for details.
API Reference
buyAmount
maxSellAmount
The response field that replaces minBuyAmount when buyAmount is used. It is the maximum amount of sellToken the taker authorizes — the swap will not spend more than this. Any unspent sell token is returned to the taker.
buyAmount and sellAmount are mutually exclusive. Passing both on the same
request will result in an error. Use one or the other.
buyAmount is not supported for wrap and unwrap operations (e.g. ETH ↔
WETH). Passing it for those trade types will result in an error. Check for
native/wrapped token pairs and use sellAmount for those cases.
Example
A payment provider wants to guarantee a merchant receives exactly 500 USDC. The buyer holds ETH on Base.
TypeScript
Python
cURL
Errors
Conflicting amount fields
Passing both buyAmount and sellAmount on the same request is not allowed.
Wrap/unwrap operations
buyAmount is not supported when sellToken and buyToken are a native/wrapped pair (e.g. ETH ↔ WETH). Use sellAmount for these operations instead.
Guard against this by detecting wrap/unwrap pairs before building your request:
Key considerations
- Taker authorizes a ceiling, not a fixed input. The taker approves up to
maxSellAmount. Any unspent sell token is returned in the same transaction — the taker never overpays. - The merchant receives exactly
buyAmount. This guarantee holds regardless of price movement between quote and settlement. - Existing integrations are unaffected.
buyAmountis opt-in. Integrations usingsellAmountcontinue to work without changes. - Wrap/unwrap is not supported. Check for native/wrapped token pairs and use
sellAmountfor those cases. - All supported chains. Exact Buy is live on every EVM chain the Swap API supports.
- Pairs naturally with Swap and Send. Use
recipientalongsidebuyAmountto deliver the exact output directly to a merchant in one transaction.