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

# initAmplifySDK

> Initialize the Amplify SDK with your API key before using any functions

All Amplify SDK functions require initialization before use. Call `initAmplifySDK()` once at application startup.

## Import

```ts theme={null}
import { initAmplifySDK } from '@paxoslabs/amplify-sdk'
```

## Usage

```ts theme={null}
await initAmplifySDK('pxl_your_api_key')
```

## Parameters

| Parameter | Type             | Required | Description                                     |
| --------- | ---------------- | -------- | ----------------------------------------------- |
| `apiKey`  | `string`         | Yes      | Your Paxos Labs API key (format: `pxl_...`)     |
| `options` | `SDKInitOptions` | No       | Configuration options for telemetry and logging |

### SDKInitOptions

```ts theme={null}
interface SDKInitOptions {
  /** Custom RPC URLs keyed by chain ID */
  rpcUrls?: Record<number, string>

  /** Enable/disable PostHog telemetry (default: true) */
  telemetry?: boolean

  /** Log level for SDK operations (default: LogLevel.ERROR) */
  logLevel?: LogLevel

  /** Custom logger implementation */
  logger?: Logger
}
```

| Option      | Type                     | Default                 | Description                                                                                                       |
| ----------- | ------------------------ | ----------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `rpcUrls`   | `Record<number, string>` | Public RPCs             | Allow custom RPCs to provide better UX and reliability. Chains without a custom RPC URL fall back to public RPCs. |
| `telemetry` | `boolean`                | `true`                  | Enable PostHog error tracking                                                                                     |
| `logLevel`  | `LogLevel`               | `LogLevel.ERROR`        | Minimum log level to output                                                                                       |
| `logger`    | `Logger`                 | Built-in console logger | Custom logger implementation                                                                                      |

## Return Type

```ts theme={null}
Promise<void>
```

## Examples

<Tabs>
  <Tab title="Basic">
    ```ts theme={null}
    import { initAmplifySDK } from "@paxoslabs/amplify-sdk";

    await initAmplifySDK("pxl_your_api_key");
    ```
  </Tab>

  <Tab title="Custom RPCs">
    ```ts theme={null}
    import { initAmplifySDK } from "@paxoslabs/amplify-sdk";
    import { mainnet, sepolia } from "viem/chains";

    await initAmplifySDK("pxl_your_api_key", {
      rpcUrls: {
        [mainnet.id]: import.meta.env.VITE_APP_ETHEREUM_MAINNET_RPC,
        [sepolia.id]: import.meta.env.VITE_APP_ETHEREUM_SEPOLIA_RPC,
      },
    });
    ```
  </Tab>

  <Tab title="With Options">
    ```ts theme={null}
    import { initAmplifySDK, LogLevel } from "@paxoslabs/amplify-sdk";

    await initAmplifySDK("pxl_your_api_key", {
      telemetry: false,
      logLevel: LogLevel.DEBUG,
    });
    ```
  </Tab>

  <Tab title="Custom Logger">
    ```ts theme={null}
    import { initAmplifySDK, LogLevel } from "@paxoslabs/amplify-sdk";

    await initAmplifySDK("pxl_your_api_key", {
      logLevel: LogLevel.DEBUG,
      logger: {
        debug: (msg, ctx) => console.debug(`[SDK] ${msg}`, ctx),
        info: (msg, ctx) => console.info(`[SDK] ${msg}`, ctx),
        warn: (msg, ctx) => console.warn(`[SDK] ${msg}`, ctx),
        error: (msg, ctx) => console.error(`[SDK] ${msg}`, ctx),
      },
    });
    ```
  </Tab>
</Tabs>

## Behavior

* **Validates API key** — Checks key format and minimum length
* **Returns immediately** — Initialization completes without blocking on network calls
* **Populates cache in background** — Accounts and assets are fetched asynchronously after init returns. Use `waitForCacheReady()` if you need guaranteed fast operations before the first SDK call
* **Configures telemetry** — Sets up PostHog if enabled (async, non-blocking)
* **Configures logging** — Sets log level and optional custom logger
* **Idempotent** — Multiple calls with same key are no-ops
* **Re-initialization** — Different key clears cache and reconfigures

## Error Handling

```ts theme={null}
try {
  await initAmplifySDK('pxl_your_api_key')
} catch (error) {
  if (error instanceof APIError) {
    console.error(`Init failed: ${error.message}`)
  }
}
```

| Error Message Pattern       | Description                | Resolution                    |
| --------------------------- | -------------------------- | ----------------------------- |
| `"API key cannot be empty"` | Empty or missing API key   | Provide a valid `pxl_...` key |
| `"Invalid API key format"`  | Key too short or malformed | Check key format              |

<Info>
  If you call other SDK functions (e.g., `prepareDepositTxData`,
  `getSupportedAssets`) before calling `initAmplifySDK()`, they will throw an
  `SDK_NOT_INITIALIZED` error. Always initialize the SDK first.
</Info>

## Related

* [Logging Guide](/v0.5.2/intro/products/earn/developers/guides/logging) - Configure logging levels
* [Project Setup](/v0.5.2/intro/products/earn/developers/guides/project-setup) - SDK initialization patterns
