> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/getting-started/choose-transport.md).

# Choose your transport

DNotifier SDKs support two transports: **WebSocket (`ws`)** and **HTTP (`http`)**. Both use the same credentials and authenticate the same way at `connect()`. The difference is how messages flow after authentication.

## Decision table

| Criterion                            | WebSocket (`ws`)                                   | HTTP (`http`)                                         |
| ------------------------------------ | -------------------------------------------------- | ----------------------------------------------------- |
| **Best for**                         | Realtime messaging, live chat, push-style delivery | AI prompts, RAG, knowledge-base APIs, workflows       |
| **Connection**                       | Persistent socket; server pushes incoming messages | Stateless request/response per call                   |
| **Incoming messages**                | Delivered to `onMessage` in real time              | Not used for push; responses return from method calls |
| **`send()` for 1:1 chat**            | ✅ Recommended                                      | ⚠️ Possible but not ideal for live UX                 |
| **`sendAI()`**                       | ❌ Use HTTP instead                                 | ✅ Recommended                                         |
| **Knowledge base (add/search/list)** | ❌ Use HTTP instead                                 | ✅ Recommended                                         |
| **`runWorkflow()`**                  | ❌ Use HTTP instead                                 | ✅ Recommended                                         |
| **Browser support**                  | Native `WebSocket` API                             | `fetch` / standard HTTP                               |
| **Node.js**                          | Requires `WebSocketImpl` (e.g. `ws` package)       | Works out of the box                                  |
| **Reconnect handling**               | Your app should handle disconnects                 | N/A — each call is independent                        |

## When to use WebSocket

Choose **`transport: "ws"`** when you need:

* **Realtime 1:1 messaging** between users, devices, or services
* **Live chat** with instant delivery to `onMessage`
* **Binary or large structured payloads** with automatic chunking over a persistent connection
* **Low-latency push** without polling

Typical apps: chat clients, live collaboration, device telemetry with bidirectional frames, notification feeds where the server initiates delivery.

```js
const notifier = new DNotifier({
  appId: process.env.DNOTIFIER_APP_ID,
  secret: process.env.DNOTIFIER_SECRET,
  transport: "ws",
  userId: "user-123",
  WebSocketImpl: WebSocket, // Node.js only
  onConnected: () => console.log("Ready for realtime"),
  onMessage: (msg) => console.log(msg.payload.toJSON()),
  onDisconnected: () => {},
});
```

## When to use HTTP

Choose **`transport: "http"`** when you need:

* **AI** — `sendAI`, session continuation, `fetchAIHistory`
* **RAG / knowledge base** — `addDocument`, `search`, `listDocuments`, etc.
* **Workflows** — `runWorkflow` with agents and observability
* **Server-side RPC** where each operation is a discrete HTTP call

Typical apps: backend AI assistants, document indexing pipelines, admin tools, cron jobs, API routes that answer a prompt and return JSON.

```js
const notifier = new DNotifier({
  appId: process.env.DNOTIFIER_APP_ID,
  secret: process.env.DNOTIFIER_SECRET,
  transport: "http",
  userId: "user-123",
  onConnected: () => console.log("Authenticated"),
  onMessage: () => {},
  onDisconnected: () => {},
});

await notifier.connect();
const response = await notifier.sendAI({
  senderId: "user-123",
  message: { text: "Summarize this ticket." },
});
```

## Can I use both?

Yes. Many production systems use **two SDK instances** (or reconnect with different transports at different lifecycle stages):

| Component  | Transport | Role                  |
| ---------- | --------- | --------------------- |
| Chat UI    | `ws`      | Realtime send/receive |
| API server | `http`    | AI, RAG, workflows    |

Use the same `appId` and `secret`, but pick the transport that matches each code path.

## Authentication is the same

Both transports call the DNotifier auth endpoint during `connect()`. You receive:

* An auth **token**
* **Plan limits** (`getPlanLimits()`)
* **`aiEnabled`** and **message size** caps

WebSocket clients then open a socket and complete a handshake. HTTP clients mark themselves connected without maintaining a socket.

## Next steps

* [**Install an SDK**](/product-docs/getting-started/installation.md) — Add the package for your language
* [**Your first connection**](/product-docs/getting-started/first-connection.md) — Connect with your chosen transport
* [**Your first message**](/product-docs/getting-started/first-message.md) — Send a 1:1 message (WebSocket)
