> For the complete documentation index, see [llms.txt](https://docs.peach.ag/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.peach.ag/api-reference/readme/prepare-delegated-swap.md).

# Swap Permit2

Prepare a Permit2 swap with a quote, frozen plan and payer signing data.

## Swap Permit2

> Return a quote, frozen plan and payer signing material. This is the first Permit2 request; SDK method: \`swapPermit2()\`. Supply different payer and executor addresses and an explicit recipient. Only ERC20 input is supported. Review and sign the returned Permit2 witness typed data, then submit the quote ID and payer signature to \`POST /router/swap/permit2/build\`. No separate quote request is required.\
> \
> Compatibility alias: \`/router/swap/prepare\`. Production deployment of the new endpoint has not been verified.

```json
{"openapi":"3.0.3","info":{"title":"BSC Aggregator HTTP API","version":"2026-10-20"},"tags":[{"name":"BSC Aggregator HTTP API","description":"Allowance: one request for a quote and executable transaction. Permit2: prepare, payer signing, then build. No prior find_routes request is required."}],"servers":[{"url":"https://api.peach.ag","description":"BSC production API (chain ID 56); operation availability follows deployment."}],"paths":{"/router/swap/permit2":{"get":{"operationId":"swapPermit2","tags":["BSC Aggregator HTTP API"],"summary":"Swap Permit2","description":"Return a quote, frozen plan and payer signing material. This is the first Permit2 request; SDK method: `swapPermit2()`. Supply different payer and executor addresses and an explicit recipient. Only ERC20 input is supported. Review and sign the returned Permit2 witness typed data, then submit the quote ID and payer signature to `POST /router/swap/permit2/build`. No separate quote request is required.\n\nCompatibility alias: `/router/swap/prepare`. Production deployment of the new endpoint has not been verified.","parameters":[{"name":"from","in":"query","required":true,"description":"Input ERC20 token address. Use WBNB for native BNB routing.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"target","in":"query","required":true,"description":"Output ERC20 token address; must differ from from. Use WBNB for native BNB routing.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"amount","in":"query","required":true,"description":"Positive unsigned integer, at most 2^128 - 1, in input-token base units for the documented exact-input flow. Send decimal digits, never a human-readable fractional amount.","schema":{"type":"string","pattern":"^[0-9]+$"}},{"name":"by_amount_in","in":"query","required":false,"description":"Use true for the documented exact-input v7 workflow. Omission defaults to true. A legacy false flag can be parsed by the server but does not establish supported exact-output behavior.","schema":{"type":"boolean","enum":[true],"default":true}},{"name":"depth","in":"query","required":false,"description":"Maximum route hops. Omission or 0 uses the service routing configuration; values above its maximum are rejected.","schema":{"type":"integer","minimum":0}},{"name":"split_count","in":"query","required":false,"description":"Requested split count. Omission or 0 uses the configured maximum; the service can reduce it for trade size and metadata availability.","schema":{"type":"integer","minimum":0}},{"name":"providers","in":"query","required":false,"description":"Comma-separated provider identifiers from Get Status. Omit to use the enabled provider set; availability and version filters still apply.","schema":{"type":"string"}},{"name":"v","in":"query","required":false,"description":"Accepted for routing compatibility; swap endpoints do not apply the find_routes minimum-version gate.","schema":{"type":"integer","minimum":0}},{"name":"gas","in":"query","required":false,"description":"Optional gas limit override. Prefer the service estimate unless you have measured the complete execution path.","schema":{"type":"integer","minimum":0}},{"name":"cal_path_limit","in":"query","required":false,"description":"Optional advanced path-calculation limit; behavior follows the service routing configuration.","schema":{"type":"integer","minimum":0}},{"name":"executor","in":"query","required":false,"description":"Transaction sender signed into the plan. executor or its compatibility alias sender is required. Submit the returned transaction from this address. Must be nonzero and differ from the execution router.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"sender","in":"query","required":false,"description":"Compatibility alias for executor. Prefer executor and send only one of the two fields. Must be nonzero and differ from the execution router.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"payer","in":"query","required":true,"description":"ERC20 token owner; must differ from executor for delegated preparation. Must be nonzero and differ from the execution router.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"recipient","in":"query","required":true,"description":"Output recipient. Required when payer differs from executor. Must be nonzero and differ from the execution router.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"custom_fee_bps","in":"query","required":false,"description":"Custom fee deducted from gross output, in basis points (100 bps=1%). Omission/0 means no fee. Must not exceed peach_router.max_custom_fee_bps from Get Status. Fees require by_amount_in=true.","schema":{"type":"integer","minimum":0,"maximum":65535}},{"name":"custom_fee_receiver","in":"query","required":false,"description":"Required when custom_fee_bps>0. Must be nonzero and differ from the execution router and recipient. For native BNB output use a recipient able to receive BNB; the service rejects contract fee receivers when its optional code check identifies one.","schema":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$"}},{"name":"slippage_bps","in":"query","required":false,"description":"Slippage applied to expected net output after the custom fee: floor(expect_amount_out*(10000-slippage_bps)/10000). Omission uses service configuration (code fallback 50 bps=0.5%).","schema":{"type":"integer","minimum":0,"maximum":9999}},{"name":"deadline_secs","in":"query","required":false,"description":"Expiry offset in seconds. Delegated preparation requires 1..configured maximum (code fallback maximum 300). Omission uses the configured default (code fallback 120).","schema":{"type":"integer","minimum":1}},{"name":"native_in","in":"query","required":false,"description":"Must be false for delegated funding; native BNB input is unsupported.","schema":{"type":"boolean","default":false}},{"name":"native_out","in":"query","required":false,"description":"Set true for native BNB output and pass WBNB as target. Cannot be combined with native_in=true.","schema":{"type":"boolean","default":false}}],"responses":{"200":{"description":"Application success (code=200) or application error (code!=200). Business errors may still have HTTP status 200; inspect the JSON code.","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/PrepareDelegatedResponse"},{"$ref":"#/components/schemas/Error"}]}}},"headers":{"Cache-Control":{"description":"Do not cache execution responses.","schema":{"type":"string"}}}},"400":{"description":"Malformed query or request rejected by HTTP extraction. Body may be plain text rather than an application envelope.","content":{"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Unhandled service failure.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Service-wide rate limit / circuit breaking. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"schemas":{"PrepareDelegatedResponse":{"type":"object","properties":{"code":{"type":"integer","enum":[200]},"msg":{"type":"string"},"data":{"$ref":"#/components/schemas/PrepareDelegatedData"}},"required":["code","msg","data"]},"PrepareDelegatedData":{"type":"object","properties":{"request_id":{"type":"string"},"quote_id":{"type":"string","pattern":"^0x[0-9a-fA-F]{64}$"},"quote_ts":{"type":"integer","minimum":0,"description":"Unix milliseconds."},"amount_in":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."},"amount_out":{"type":"string","pattern":"^[0-9]+$","description":"Gross output before custom fees."},"expect_amount_out":{"type":"string","pattern":"^[0-9]+$","description":"Expected net output after custom fees, before slippage."},"amount_out_min":{"type":"string","pattern":"^[0-9]+$","description":"Prepared minimum net output after slippage. Validate it against signed calldata after build."},"payer":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"executor":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"recipient":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"gas":{"type":"integer","minimum":0},"execution_mode":{"type":"string","enum":["PERMIT2_WITNESS"]},"execution_status":{"type":"string","enum":["PAYER_SIGNATURE_REQUIRED"]},"plan_hash":{"type":"string","pattern":"^0x[0-9a-fA-F]{64}$"},"aggregator_signature":{"type":"string","pattern":"^0x(?:[0-9a-fA-F]{2})*$"},"aggregator_signer":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"payer_authorization":{"$ref":"#/components/schemas/PayerAuthorization"}},"required":["request_id","quote_id","quote_ts","amount_in","amount_out","expect_amount_out","amount_out_min","payer","executor","recipient","gas","execution_mode","execution_status","plan_hash","aggregator_signature","aggregator_signer","payer_authorization"],"description":"The service freezes quote, route, roles and signed plan for the prepare/build flow. No ready transaction is returned at this stage."},"PayerAuthorization":{"type":"object","properties":{"scheme":{"type":"string","enum":["PERMIT2_WITNESS_TRANSFER"]},"owner":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"permit2":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"spender":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"Execution router authorized as Permit2 spender; equals the signed plan router and final tx.to."},"token":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"amount":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."},"nonce":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."},"deadline":{"type":"integer","minimum":0,"description":"Absolute Unix expiry in seconds."},"witness_plan_hash":{"type":"string","pattern":"^0x[0-9a-fA-F]{64}$"},"typed_data":{"$ref":"#/components/schemas/Permit2TypedData"}},"required":["scheme","owner","permit2","spender","token","amount","nonce","deadline","witness_plan_hash","typed_data"]},"Permit2TypedData":{"type":"object","properties":{"domain":{"type":"object","properties":{"name":{"type":"string","enum":["Permit2"]},"chainId":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."},"verifyingContract":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."}},"required":["name","chainId","verifyingContract"]},"types":{"type":"object","additionalProperties":{"type":"array","items":{"$ref":"#/components/schemas/TypedDataField"}},"description":"EIP-712 definitions for EIP712Domain, TokenPermissions, PeachExecutionWitness and PermitWitnessTransferFrom."},"primaryType":{"type":"string","enum":["PermitWitnessTransferFrom"]},"message":{"type":"object","properties":{"permitted":{"type":"object","properties":{"token":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"20-byte EVM address, prefixed with 0x."},"amount":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."}},"required":["token","amount"]},"spender":{"type":"string","pattern":"^0x[0-9a-fA-F]{40}$","description":"Execution router authorized to spend this Permit2 witness transfer."},"nonce":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."},"deadline":{"type":"string","pattern":"^[0-9]+$","description":"Unsigned integer encoded as a decimal string; token amounts use integer base units."},"witness":{"type":"object","properties":{"planHash":{"type":"string","pattern":"^0x[0-9a-fA-F]{64}$"}},"required":["planHash"]}},"required":["permitted","spender","nonce","deadline","witness"]}},"required":["domain","types","primaryType","message"],"description":"Sign the returned EIP-712 payload as the payer after checking chain, Permit2, token, amount, spender, deadline and witness. Do not replace any fields."},"TypedDataField":{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string"}},"required":["name","type"]},"Error":{"type":"object","properties":{"code":{"type":"integer","minimum":0,"maximum":65535,"not":{"enum":[200]},"description":"Application result code, distinct from HTTP status. See Error Codes."},"msg":{"type":"string","description":"Human-readable explanation."}},"required":["code","msg"],"description":"Application errors omit data. Business errors normally use HTTP 200; check code==200 before consuming data."}}}}
```

### Integration notes

Supply distinct `payer` and `executor` addresses (or the `sender` alias), plus an explicit `recipient`. Only ERC20 input is supported (`native_in=false`); native output uses WBNB in `target` with `native_out=true`.

The payer approves the input ERC20 to canonical Permit2, reviews and signs `payer_authorization.typed_data`, then sends the returned `quote_id` and signature to [Swap Permit2 Build](https://docs.peach.ag/api-reference/readme/build-delegated-swap). The raw `amount_out_min` is not a substitute for validation against signed calldata after build. Each preparation creates a new plan; keep its artifacts together. This endpoint does not broadcast.

The payer signature authorizes the frozen plan. See [Delegated Swaps](https://docs.peach.ag/documentation/bsc/aggregator/editor/delegated-execution-with-permit2-witness) for the signing boundary.

Check both the HTTP status and JSON `code`; a business error may use HTTP 200. See [Error Codes](https://docs.peach.ag/api-reference/readme/error-codes) for recovery guidance. Invalid query or body extraction may return plain text instead of the JSON envelope.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.peach.ag/api-reference/readme/prepare-delegated-swap.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
