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

# Bring your own AI plan

> Let your app's users power its AI features with their own ChatGPT or Cursor plan, so your app pays for no AI.

`@daex-dev/sdk/connect` adds **Sign in with ChatGPT** and **Sign in with Cursor** to your app. A user signs in once, from a web page, desktop app or phone. Your server keeps the sign-in sealed and renewed, and makes AI calls with it on the user's own plan. This entry point does not start a DAEX runtime.

| Provider | What the user signs in with | What it spends |
| - | - | - |
| ChatGPT | OpenAI's Sign in with ChatGPT | The user's ChatGPT Plus or Pro plan |
| Cursor | Cursor's SDK sign-in (a 90-day key) | The user's Cursor plan |

## Server

```ts theme={null}
import { createConnectHandler, createConnectVault, provideCursorSdk } from "@daex-dev/sdk/connect";

provideCursorSdk(() => import("@cursor/sdk")); // only if you offer Cursor: npm install @cursor/sdk

const vault = createConnectVault({
  storage: yourKeyValueStore,           // get / set / delete, optional lock for several instances
  secret: process.env.CONNECT_SECRET!,  // at least 32 bytes
});

const handler = createConnectHandler({
  vault,
  appName: "My App",
  hostId: process.env.CONNECT_HOST_ID!, // newCodexHostId(), generated once
  getUserId: (request) => yourSession(request)?.userId ?? null,
});
```

`handler` is a Fetch API handler that returns `null` for paths outside `/connect`. On Node or Express, mount it with `app.use(toNodeListener(handler))`. In a Next.js route, return a 404 for `null`.

## Page

```ts theme={null}
import { createConnectClient } from "@daex-dev/sdk/connect/browser";

const connect = createConnectClient({ baseUrl: "/connect" });
const { providers } = await connect.providers();   // buttons + each provider's sign-in status

await connect.signIn("cursor");
await connect.signIn("codex", { askForRedirectUrl: () => askUserToPaste() });

for await (const event of connect.respond({ provider: "codex", prompt: "Summarize my notes" })) {
  if (event.type === "text") append(event.delta);
}
```

OpenAI sends the browser back to `http://127.0.0.1:…` after a ChatGPT sign-in. A web page can't receive that, so the tab shows a page that can't load, and the user pastes its address. A desktop app catches the redirect itself with `signInWithCodexOnThisDevice`.

## Requests

| Field | ChatGPT | Cursor |
| - | - | - |
| `model` | Any model the plan lists (`models()`); default: the first | Any catalog model; default: Cursor's Auto |
| `effort` | `reasoning.effort` | The model's effort parameter |
| `responseFormat` | JSON schema, enforced by OpenAI | JSON schema, given as an instruction |
| `rawEvents` | Every OpenAI event | Every Cursor SDK message |
| `codex` | Any Responses API field, merged last | None |
| `cursor` | None | `params` (model parameters), `agent`, `send` |

On the server, `createConnectAI({ vault }).respond(userId, request)` does the same without HTTP. From a browser, the handler takes the model, instructions, messages, effort, format and Cursor `params`. Raw `codex` fields and Cursor `agent` / `send` options act with your server's authority (Cursor's MCP servers are processes on your server), so a page can't set them. Pass them on in `prepareRequest` when you want to.

## Errors

Every failure is a `ConnectError` with a `code`:

| Code | Show |
| - | - |
| `not_signed_in`, `sign_in_required` | The sign-in button |
| `usage_limit` | The plan's limit, with `manageUrl` |
| `plan_not_eligible`, `plan_usage_disabled` | Why the plan can't be used here |
| `provider_unavailable` | Try again later |
| `cancelled` | Nothing; the caller stopped it |

## Storage and security

* Each sign-in is sealed with AES-256-GCM under a key derived from your secret. A row copied to another user's key does not open, and keys hold a hash of the user ID.
* ChatGPT refresh tokens rotate on every use. The vault runs refreshes, saves and sign-outs of a sign-in one at a time, so a refresh never undoes a sign-out. With several server instances, give the storage a `lock`.
* POSTs must be `application/json`, so a cross-site form can't act for a signed-in user.
* Cursor runs on an in-memory file tree, and each run's folder is deleted when it ends, so no conversation stays on your server's disk.


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