> 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/error-codes.md). Agents can also search and read this documentation through its [MCP server](https://docs.peach.ag/~gitbook/mcp).

# Error Codes

Handle HTTP failures and application error codes returned by the BSC Aggregator.

Check the HTTP status first, then the JSON `code` when an application response is available. Only `code: 200` indicates success. A business error can use HTTP status 200, with `data` omitted:

```json
{
  "code": 4000,
  "msg": "Amount cannot be zero"
}
```

### Application codes

| Code   | Meaning                               | Action                                                                        |
| ------ | ------------------------------------- | ----------------------------------------------------------------------------- |
| `200`  | Success                               | Consume `data` after validating the response                                  |
| `4000` | Invalid request                       | Check token pair, amount, version, roles, fee settings and expiry             |
| `4030` | Request forbidden                     | Check the request and applicable service restrictions                         |
| `4040` | Target token identified as a honeypot | Stop the swap and show the service explanation                                |
| `5000` | Internal application error            | Retry with backoff; retain diagnostic information                             |
| `5010` | No route or insufficient liquidity    | Adjust the amount or token pair, or retry later                               |
| `5030` | Application unavailable               | Retry with backoff; the builder or execution configuration may be unavailable |
| `5040` | Unsupported API version               | Check the client `v` parameter                                                |
| `400`  | Generic application failure           | Read `msg`; do not assume it is an HTTP status                                |

Messages describe the particular failure and are not a stable enumeration. For example, `find_routes` rejects a missing or too-small `v` with `4000`; it does not necessarily use `5040` for that check.

### HTTP failures

| HTTP status | Meaning                                       | Action                                                                  |
| ----------- | --------------------------------------------- | ----------------------------------------------------------------------- |
| `400`       | Malformed query or request extraction failure | Fix the request; the response may be plain text                         |
| `413`       | Build request exceeds the 4 KiB body limit    | Send only `quote_id` and `payer_signature` in the JSON body             |
| `415`       | Unsupported request content type              | Send `/router/swap/permit2/build` with `Content-Type: application/json` |
| `422`       | Invalid JSON body or field types              | Check the build request body; the response may be plain text            |
| `500`       | Unhandled service failure                     | Retry with backoff; the application envelope may contain `code: 500`    |
| `503`       | Service rate limit or circuit breaking        | Retry with backoff; the application envelope contains `code: 503`       |

Gateways and network failures may return other statuses or non-JSON bodies. Check the content type before parsing JSON and preserve the HTTP status for diagnostics.

### Delegated preparation and build

Preparation requires distinct `payer` and `executor` addresses, an explicit `recipient`, ERC20 input and a deadline within the service limit. Build requires a valid bytes32 `quote_id` and a 64-byte compact or 65-byte ECDSA `payer_signature` in the JSON body.

An expired or missing artifact, or an exceeded per-quote build-attempt limit, requires a new preparation and payer signature. Build accepts signature bytes for calldata construction; successful build does not establish on-chain authorization or successful execution.

Never put `payer_signature` in URLs, logs or support messages. For diagnosis, retain the endpoint, HTTP status, application `code`/`msg` and available `request_id` or response trace headers.


---

# 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/error-codes.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.
