> ## Documentation Index
> Fetch the complete documentation index at: https://docs.parlayx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> Handle API errors with the typed RequestError

Resource methods throw a `RequestError` for any non-2xx response, so you handle
failures with `try`/`catch` rather than inspecting each result. On success, a
method resolves with its typed payload.

`RequestError` exposes:

* **`code`** — a stable [`ApiErrorCode`](/api-reference) (e.g. `INVALID_REQUEST`,
  `INSUFFICIENT_BALANCE`, `NOT_FOUND`), so you can branch on an enum instead of
  parsing strings. It is `undefined` for errors raised before a handler runs.
* **`status`** — the HTTP status code.
* **`message`** — a human-readable explanation.

```ts theme={null}
import { createClient, RequestError } from "@parlayx/sdk";

const client = createClient({ apiKey: process.env.PARLAYX_API_KEY! });

try {
  const balance = await client.getBalance();
  console.log(balance.cash);
} catch (error) {
  if (!(error instanceof RequestError)) throw error;

  switch (error.code) {
    case "INSUFFICIENT_BALANCE":
      console.error("Not enough spendable balance:", error.message);
      break;
    case "NOT_FOUND":
      console.error("Resource not found:", error.message);
      break;
    default:
      console.error(`Request failed (${error.status}):`, error.message);
  }
}
```

Authentication failures are returned by the gateway before a handler runs: they
surface as a `RequestError` with `status` `403` and no `code` — check `status`
in that case.
