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

# Introduction to the Benji Connect SDK

> An SDK that simplifies connectivity to reward partners.

![title](https://mintcdn.com/benji/1bAF2v-oOLtjOiGn/images/connect/connect_flow.png?fit=max\&auto=format\&n=1bAF2v-oOLtjOiGn\&q=85\&s=16a645702fadb66c9474cd221e255cd7)

## Overview

The Benji Connect SDK is a JavaScript/TypeScript library that opens a **modal** to the Benji Connect experience. After your user completes the flow, you receive a short-lived token to [exchange](https://docs.withbenji.com/connect/exchange_token.md) for API access, plus structured metadata about the user and any transaction context.

**Connect modes** (what the user is doing in the UI—link account, transfer points, redeem points) are determined by the [connect token](https://docs.withbenji.com/connect/create_token.md) you create on your server (`mode` and optional `custom_attributes`). See [Connect modes](https://docs.withbenji.com/connect/modes.md) for values and usage. That is separate from your **partnership type** in Pilot (e.g. [Direct vs Marketplace](https://docs.withbenji.com/pilot/concepts.md)), which describes how the partnership is sourced.

> [!TIP]
>
> The connect token encodes mode, partnership, and user hints. You create it with your **partner API key** ([Pilot Developer](https://docs.withbenji.com/pilot/developer.md)) via the [Create Token](https://docs.withbenji.com/connect/create_token.md) API.

### Benji Connect flow

1. [Create a connect token](https://docs.withbenji.com/connect/create_token.md) on your server (`partnership_id`, `mode`, optional `user_external_id`, optional `custom_attributes`, etc.).
2. [Initialize the Benji Connect SDK](https://docs.withbenji.com/connect/initialization.md) with that token, your [environment](https://docs.withbenji.com/connect/initialization.md) (`development` | `sandbox` | `production`), and optional callbacks (`onSuccess`, `onError`, `onExit`, `onEvent`).
3. Call **`open()`** when the user starts Connect (e.g. button click). The **Benji Connect SDK** presents the Connect flow in that modal; the Connect URL includes your token as **`connect_token`** (same idea as [**Benji Hosted Connect**](https://docs.withbenji.com/connect/hosted/introduction.md) query parameters).
4. [Handle callbacks](https://docs.withbenji.com/connect/methods.md): completion and errors are described in the Methods & Events page (`onSuccess` receives the exchange token after **`FLOW_SUCCESS`**).
5. [(Optional) Exchange the token](https://docs.withbenji.com/connect/exchange_token.md) from **`onSuccess`** for long-lived `access_token` / `refresh_token` pairs for user-scoped Benji APIs.

> [!WARNING]
>
> Treat access and refresh tokens as secrets. Store them securely and rotate using the refresh flow when access tokens expire.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.