# Error Codes


> Understand BayarGO API error responses and codes.

Canonical: https://docs.bayargo.id/errors

Failed requests return RFC 9457 problem details with the media type
`application/problem+json`. The stable `code` identifies the error; `detail` is
safe to show to the caller, and `request_id` is the correlation ID to include
when contacting support.

```json
{
  "type": "https://api.bayargo.id/problems/invalid_api_key",
  "title": "Unauthorized",
  "status": 401,
  "code": "invalid_api_key",
  "detail": "secret key is invalid or revoked",
  "request_id": "req_0123456789abcdef"
}
```

## Public API

| HTTP | Code | Description |
| --- | --- | --- |
| `400` | `invalid_json` | Body is not valid JSON. |
| `400` | `invalid_amount` | Amount is invalid. |
| `400` | `invalid_bulk_size` | Bulk item count is invalid. |
| `400` | `unsupported_payment_method` | Payment method is not supported. |
| `400` | `payment_create_failed` | Transaction could not be created. |
| `400` | `payment_cancel_failed` | Transaction could not be cancelled. |
| `400` | `payment_refund_failed` | Transaction could not be refunded. |
| `401` | `invalid_api_key` | Secret key is missing, invalid, or revoked. |
| `403` | `merchant_not_approved` | Merchant is not active. |
| `403` | `api_key_ip_not_allowed` | Request IP is not in the API key allowlist. |
| `404` | `not_found` | Resource was not found. |
| `429` | `rate_limited` | Rate limit exceeded. |
| `500` | `server_error` | Request could not be processed. |

## Rate Limit

The API applies rate limits to keep the service stable.
If a response includes `Retry-After`, wait at least that many seconds before retrying. Otherwise,
pause before retrying and use exponential backoff for repeated failures. For a retried create-
payment request, reuse its original `Idempotency-Key`.

## Retry

| Condition | Retry |
| --- | --- |
| Timeout | Yes, use the same request. |
| `500` | Yes, after a delay. |
| `400`, `401`, `403`, `404` | No. Fix the request or merchant status. |
| `429` | Yes, after waiting for the next rate-limit window. |
