Skip to main content
This tutorial shows how an autonomous AI agent (running in a loop, triggered by events, or driven by an LLM) can create and manage orders on CoW Protocol through the REST API. By the end you will have a working Python script that:
  1. Fetches a quote
  2. Applies slippage protection
  3. Signs the order (EIP-712)
  4. Submits it to the order book
  5. Monitors execution with proper error recovery
This guide builds on the same API flow as the Raw API (cURL) and Python quickstarts. If you have not placed an order before, start there.

Prerequisites

Before starting, make sure your agent has access to:
  • A private key for an EOA wallet (stored securely — environment variable or secrets manager)
  • ETH on the target chain — only needed for token approval transactions, not for order submission
  • Tokens to trade — the sell token must already be in the wallet. Any ERC-20 token is tradeable, not just those on the CoW token list (the list is used by the UI for display purposes)
  • Token approval for the GPv2VaultRelayer (0xC92E8bdf79f0507f65a392b0ab4667716BFE0110) to spend the sell token
  • Python 3.8+ with requests, web3, and eth-account installed
API base URLs by network:
Never hardcode private keys. Use os.environ.get("PRIVATE_KEY") in Python (not string interpolation or shell expansion) to avoid exposing secrets in process argument lists visible via ps. Avoid passing keys as command-line arguments (e.g., python script.py --key 0x...). For production agents, use a secrets manager.
Want to trade native ETH (not WETH)? You can use Eth-flow to place orders selling native ETH directly, without wrapping to WETH first.

Walkthrough

Agent-specific considerations

Rate limiting

The CoW Protocol API enforces per-IP rate limits. Key limits for agent workflows: Always implement exponential backoff with jitter for 429 responses. See the full Rate Limits & Quotas reference for details and backoff code examples.

Quote freshness

Quotes reflect current market conditions and expire. For agents:
  • Re-quote if the agent delays materially between quoting and submission, even if validTo has not been reached yet.
  • Re-quote whenever the agent changes any input that affects execution, such as the token pair, amount, or slippage settings.
  • Treat quote data as short-lived state: cache it only within the current decision loop and refresh it before signing if conditions have changed.

Error recovery

Your agent should handle these HTTP responses:

Idempotency

Order UIDs are deterministic — derived from the order parameters and signer address. Submitting the same signed order twice returns the same UID without creating a duplicate. This means:
  • Your agent can safely retry a failed submission without risking double-execution.
  • If your agent crashes between signing and confirming submission, it can resubmit the same signed payload on restart.

Gas management

CoW Protocol orders are off-chain intents. Submitting and monitoring orders requires zero gas. Your agent only needs ETH for:
  • Token approvals — a one-time approve() transaction per sell token for the GPv2VaultRelayer
  • On-chain cancellations — if you cancel via the settlement contract instead of the API (optional)
For most agent workflows, a single approval per token is sufficient. The agent itself does not pay gas for trade execution — solvers handle that.

Complete example

A minimal Python script that runs the full flow:

Next steps

Last modified on March 17, 2026