## Errors

Every error has the same shape. Branch on `code`; `message` is for people and
its wording can change.

```json
{
  "error": {
    "code": "invalid_signature",
    "message": "signature was not made by GP8Z… over this quote's `message`"
  }
}
```

| Code                   | Status | What to do                                                                                  |
| ---------------------- | ------ | ------------------------------------------------------------------------------------------- |
| `invalid_request`      | 400    | Fix the field `message` names: a missing value, an amount with too many decimals, a bad cursor. |
| `invalid_address`      | 400    | Use a Solana address, an EVM `0x` address or a GUM address. For withdrawals, check `destination`. |
| `unsupported_account`  | 400    | The address belongs to a Google, Apple, X or passkey account. Trade with a Solana or EVM wallet. |
| `unsupported_chain`    | 400    | Use a chain from `GET /v1/chains`. USD can't be withdrawn to BSC or Robinhood.              |
| `token_not_found`      | 404    | Find the token's address with `GET /v1/tokens`.                                             |
| `quote_failed`         | 400    | No route right now: the amount may be too small, or the token too illiquid. Try again later or change the amount. |
| `quote_expired`        | 400    | Quotes last about 30 seconds. Get a new quote, sign it and submit right away.               |
| `invalid_transaction`  | 400    | Send the quote's `transaction` unchanged, to the matching endpoint (`/swap` or `/withdraw`). |
| `invalid_signature`    | 401    | Sign `message` with the account in `signer.address`. See [Sign with your wallet](/trading-api/signing). |
| `submit_failed`        | 400    | The trade or withdrawal was rejected, for example for an insufficient balance. Read `message`. |
| `not_found`            | 404    | Unknown endpoint or id. `GET /v1` lists every endpoint.                                     |
| `method_not_allowed`   | 405    | Quotes and submissions are `POST`s with a JSON body.                                        |
| `rate_limited`         | 429    | Wait `Retry-After` seconds.                                                                 |
| `too_many_streams`     | 429    | Close a live stream, or poll instead.                                                       |
| `upstream_unavailable` | 502, 503 | A GUM service didn't answer. Retry with backoff.                                          |
| `internal_error`       | 500    | Retry with backoff; report it on [Discord](https://discord.gg/gum-ag) if it persists.       |

<Warning>
  A submit that times out or returns a 5xx may still have gone through. Check
  [`GET /v1/history/{address}`](/trading-api/reference/get-history) before you
  submit again, so you don't trade twice. A quote can only be submitted once.
</Warning>

## Rate limits

Limits are per IP address, per minute. Every request counts toward the overall
limit, and some also count toward a tighter one:

| What                                     | Limit           |
| ---------------------------------------- | --------------- |
| All requests                             | 120 per minute  |
| Quotes (`/swap/quote`, `/withdraw/quote`) | 30 per minute   |
| Submissions (`/swap`, `/withdraw`)       | 20 per minute   |
| Deposit-address lookups                  | 10 per minute   |
| Open live streams (`/events`)            | 10 at a time    |

Every response reports the limit closest to running out:

| Header                | Meaning                                      |
| --------------------- | -------------------------------------------- |
| `RateLimit-Limit`     | Requests allowed in the current window       |
| `RateLimit-Remaining` | Requests left in the current window          |
| `RateLimit-Reset`     | Seconds until the window resets              |
| `Retry-After`         | On a 429: seconds to wait before retrying    |

To stay under the limits, stream status instead of polling it, and quote only
when you're about to trade. If you need more, ask on
[Discord](https://discord.gg/gum-ag).
