API Integration
The CoW Protocol API provides direct access to the protocol's functionality through RESTful endpoints. This approach offers maximum flexibility and control for backend integrations and custom implementations.
Overview
The API integration allows you to interact with CoW Protocol at the lowest level, giving you complete control over order management, quote fetching, and trade execution. This is ideal for advanced integrations, backend services, and custom trading logic.
Key APIs
Order Book API
The primary API for creating and managing orders on CoW Protocol.
- Base URL:
https://api.cow.fi/ - Purpose: Quote generation, order submission, order management
- Authentication: No API key required for basic operations
Key Endpoints
POST /api/v1/quote- Get trading quotesPOST /api/v1/quote/stream- Stream progressively improving quotes as solvers respond (SSE)POST /api/v1/orders- Submit signed ordersGET /api/v1/orders/{uid}- Get order detailsDELETE /api/v1/orders/{uid}- Cancel ordersGET /api/v1/trades- Get trade history
Quick Start Example
1. Get a Quote
curl -X POST "https://api.cow.fi/mainnet/api/v1/quote" \
-H "Content-Type: application/json" \
-d '{
"sellToken": "0xA0b86a33E6411Ec5d0b9dd2E7dC15A9CAA6C1F8e",
"buyToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"sellAmountBeforeFee": "1000000",
"kind": "sell",
"from": "0xYourWalletAddress"
}'
The amounts in the response already have network costs and the protocol fee deducted. Read Displaying and Comparing Quotes before showing them to users.
2. Sign and Submit Order
Build the order from quoteResponse.quote, not from the whole response. For a sell order, sign the full sell amount with feeAmount: "0" and reduce the buy amount by the slippage tolerance (see Forming the Final Order):
const { quote } = quoteResponse
const slippageBps = 50n // 0.5%
const order = {
sellToken: quote.sellToken,
buyToken: quote.buyToken,
receiver: quote.receiver,
// quote.sellAmount is after network costs; sign the full amount
sellAmount: (BigInt(quote.sellAmount) + BigInt(quote.feeAmount)).toString(),
// minimum to receive
buyAmount: (BigInt(quote.buyAmount) * (10000n - slippageBps) / 10000n).toString(),
validTo: quote.validTo,
appData: quote.appDataHash ?? quote.appData, // signed as the bytes32 hash
feeAmount: "0", // network costs are taken from sellAmount at settlement
kind: quote.kind,
partiallyFillable: quote.partiallyFillable,
sellTokenBalance: quote.sellTokenBalance,
buyTokenBalance: quote.buyTokenBalance,
}
// Submit the signed order (see Order Signing below)
const response = await fetch('https://api.cow.fi/mainnet/api/v1/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
...order,
appData: quote.appData, // full app data JSON, if the quote request included it
from: quoteResponse.from,
quoteId: quoteResponse.id,
signature: await signOrder(order, signer),
signingScheme: "eip712",
})
})
const orderId = await response.text()
3. Monitor Order Status
// Check order status
const orderResponse = await fetch(
`https://api.cow.fi/mainnet/api/v1/orders/${orderId}`
)
const orderDetails = await orderResponse.json()
console.log('Order status:', orderDetails.status)
Displaying and Comparing Quotes
The /quote amounts are not "amount out" values that can be dropped into a generic quote UI as-is.
This section covers what to display and how to rank a CoW Protocol quote against other sources.
For the full derivation of every amount stage, see How Intents Are Formed.
What the amounts mean
For a sell order:
| Field | Meaning |
|---|---|
quote.sellAmount | Sell amount after network costs (sellAmountBeforeFee - feeAmount) |
quote.feeAmount | Estimated network costs, in sell token atoms |
quote.buyAmount | Buy amount after network costs and the protocol fee (protocolFeeBps) |
Partner fees are not included; your integration applies them on top.
The user pays no separate gas for a CoW Protocol order (apart from a token approval, if one is needed): network costs are taken from the sell amount at settlement.
quote.buyAmount is therefore an after-gas amount.
Comparing with other aggregators
Other aggregators typically return their output amount before gas, and the user pays gas separately in the native token.
Putting quote.buyAmount in the same column compares an after-gas amount with before-gas amounts, so CoW Protocol ranks last even when its price is the same.
Convert every source to the same basis:
-
Before network costs, comparable to other aggregators' output amount: add the network costs back, converted to the buy token, then subtract your partner fee.
const networkCostsInBuyToken = buyAmount * feeAmount / sellAmount // quote.* amounts as BigInt
const amountBeforeNetworkCosts = buyAmount + networkCostsInBuyToken - partnerFeeAmount -
After network costs, what the user actually receives:
quote.buyAmount - partnerFeeAmount. Compare it with other sources' output minus their gas cost, converted to the buy token.
partnerFeeAmount is zero unless your integration charges a partner fee. It is computed on beforeAllFees, not on quote.buyAmount (see Partner Fee).
Don't rank on beforeAllFees (the spot price). Besides the network costs, it also adds back the protocol fee and leaves out the partner fee, so it shows more than the user can receive and overstates CoW Protocol against other sources.
Executed amounts are often better than quoted: feeAmount is an estimate made at quote time, and solvers competing in the auction return any surplus they find to the user.
Example
Selling 10 USDT for USDC on mainnet. The numbers are illustrative; network costs depend on the gas price at quote time.
{
"quote": {
"sellAmount": "9572139",
"feeAmount": "427861",
"buyAmount": "9562076",
"kind": "sell"
},
"protocolFeeBps": "0.3"
}
| Amount | USDC |
|---|---|
After network costs: quote.buyAmount | 9.562 |
Network costs in buy token: 9.562076 × 0.427861 / 9.572139 | 0.427 |
| Before network costs | 9.989 |
Another aggregator returning 9.988 USDC, with about 0.43 USD of gas paid separately in ETH, is on par with CoW Protocol on either basis: 9.989 vs 9.988 before gas, 9.562 vs about 9.558 after gas. Showing 9.562 next to 9.988 makes CoW Protocol look about 4% worse than it is.
Buy orders
For buy orders, quote.buyAmount is the fixed amount the user receives, and quote.sellAmount includes the protocol fee but not network costs.
The amount the user pays is quote.sellAmount + quote.feeAmount, plus any partner fee and slippage tolerance.
See Flow for buy orders.
Using the SDK
getQuoteAmountsAndCosts computes every amount stage from a quote response, for both sell and buy orders:
import { getQuoteAmountsAndCosts } from '@cowprotocol/cow-sdk'
const amounts = getQuoteAmountsAndCosts({
orderParams: quoteResponse.quote,
protocolFeeBps: Number(quoteResponse.protocolFeeBps),
partnerFeeBps: 0, // your partner fee, if any
slippagePercentBps: 50,
})
// Before network costs, comparable to other aggregators (sell order)
const displayAmount = amounts.beforeNetworkCosts.buyAmount - amounts.costs.partnerFee.amount
// Amounts to sign in the order
const { sellAmount, buyAmount } = amounts.amountsToSign
Streaming Quotes
POST /api/v1/quote/stream takes the same request body as POST /api/v1/quote, but returns a Server-Sent Events stream instead of a single response.
The first event arrives as soon as the fastest solver responds, and after that a quote is only emitted when it ranks better than the best one already sent, so the client can show a price immediately and every update improves on the last.
Each event's data is an OrderQuoteResponse, the same shape POST /api/v1/quote returns.
The id on each event can be passed as quoteId when placing an order, the same as a quote from POST /api/v1/quote.
The endpoint always queries all solvers and attempts verification (the request's priceQuality is ignored), and each event carries its own verified flag.
A verified quote ranks above an unverified one regardless of the quoted amount, because unverified quotes often over-promise; a later event may therefore report a slightly worse price than an earlier one when it is the first verified quote.
Solvers without a usable quote, and quotes that do not beat the best already sent, emit no event, so the stream may contain fewer events than there are solvers.
Individual solver failures are not streamed; only if no solver returns a usable quote at all does the server send a final error event with a PriceEstimationError body (for example NoLiquidity), then close.
Because every event improves on the previous one, the last event received when the stream closes is the best available quote — clients do not need to rank events themselves.
curl -N -X POST "https://api.cow.fi/mainnet/api/v1/quote/stream" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"sellToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"buyToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"sellAmountBeforeFee": "1000000000000000000",
"kind": "sell",
"from": "0xYourWalletAddress"
}'
Choosing a timeout
The first quote is delivered as soon as the fastest solver responds, so a usable price arrives faster than with POST /api/v1/quote, which waits for the whole competition.
Streaming does not make any solver compute faster, though.
The final quote is only as good as the responses that arrived before the stream was closed, and the timeout sets that boundary.
The stream stays open until the request timeout elapses or every solver has responded.
Slower solvers sometimes return a better price, especially on thin or unusual pairs that only one or two solvers can quote.
A short timeout returns sooner, but it can yield a worse quote or none at all.
A longer timeout gives the competition time to find a better price.
This tradeoff is controlled by the client through the timeout.
The value is set (in milliseconds) on the request, or the connection is closed once a good-enough quote has arrived.
The table below is a starting point, not a guarantee. The values should be measured against real traffic and raised for pairs that only slower solvers can price. Response times also differ by network, and these values shift as solver performance changes (guidance as of 2026-06).
| Network | timeout (ms) |
|---|---|
| Base, Gnosis Chain, Linea | 1000 |
| Mainnet, BNB Chain | 1800 |
| Arbitrum, Polygon, Avalanche, Ink | 2500 |
Network Endpoints
CoW Protocol APIs are available on multiple networks:
- Mainnet:
https://api.cow.fi/mainnet/api/v1/ - Gnosis Chain:
https://api.cow.fi/xdai/api/v1/ - Arbitrum:
https://api.cow.fi/arbitrum_one/api/v1/ - Base:
https://api.cow.fi/base/api/v1/ - Sepolia (Testnet):
https://api.cow.fi/sepolia/api/v1/
Order Signing
Orders must be cryptographically signed before submission. The signing process involves:
- EIP-712 Domain: Chain-specific domain separator
- Order Struct: Structured order data
- Signature: ECDSA signature or pre-signed order
import { ethers } from 'ethers'
// Example order signing with ethers.js
const domain = {
name: 'Gnosis Protocol',
version: 'v2',
chainId: 1,
verifyingContract: '0x9008D19f58AAbD9eD0D60971565AA8510560ab41'
}
const types = {
Order: [
{ name: 'sellToken', type: 'address' },
{ name: 'buyToken', type: 'address' },
{ name: 'receiver', type: 'address' },
// ... other order fields
]
}
const signature = await signer._signTypedData(domain, types, orderData)
Error Handling
The API returns standard HTTP status codes:
- 200: Success
- 400: Bad Request (invalid parameters)
- 404: Order not found
- 429: Rate limited
- 500: Internal server error
try {
const response = await fetch(apiUrl, requestOptions)
if (!response.ok) {
const error = await response.json()
throw new Error(`API Error: ${error.description}`)
}
return await response.json()
} catch (error) {
console.error('Order submission failed:', error)
}
When to Use the API
- Backend integration: Server-side order management
- Custom trading logic: Advanced order types and strategies
- High-frequency trading: Programmatic order placement
- Multi-chain applications: Cross-chain arbitrage and liquidity
- Analytics platforms: Order and trade data analysis
Rate Limits
- Quote requests: 10 requests/second
- Order submission: 5 requests/second
- General endpoints: 100 requests/minute
Next Steps
For complete API documentation including all endpoints, parameters, and response schemas, see:
- Order Book API Reference - Complete endpoint documentation
- API Documentation - Interactive API explorer
Resources
- Order Book API Reference - Detailed API documentation
- API Explorer - Interactive documentation
- GitHub Examples - Code examples
- Order Signing Guide - Cryptographic signing details
- How Intents Are Formed - Quote amount stages, fees, and the amounts to sign