> 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/ai/send-prompt.md).

# Send a prompt

The simplest AI integration is a **single prompt** via `sendAI`. You pass a `message` object (usually `{ text: "..." }`), and the SDK returns the AI response from the HTTP call.

## Requirements

| Requirement | Details                                                                   |
| ----------- | ------------------------------------------------------------------------- |
| Transport   | **`http`** — required for request/response AI                             |
| Connection  | `await connect()` before `sendAI`                                         |
| Plan        | `aiEnabled === true` after connect                                        |
| `senderId`  | Must match your connecting `userId` (or explicit id for service accounts) |

{% hint style="warning" %}
Use **`transport: "http"`** for AI. WebSocket transport sends frames but does not return AI responses the same way — HTTP is the supported path for prompts.
{% endhint %}

## Message shapes

`sendAI` accepts a flexible `message` payload:

| Shape         | Example                                       | Use case                                                                                |
| ------------- | --------------------------------------------- | --------------------------------------------------------------------------------------- |
| Simple text   | `{ text: "Summarize this." }`                 | One-shot instructions                                                                   |
| Chat messages | `{ messages: [{ role, content }] }`           | Multi-role prompts — see [Chat-style messages](/product-docs/ai/chat-style-messages.md) |
| With RAG      | `{ useKnowledgeBase: true, messages: [...] }` | Grounded answers                                                                        |

## Method signature

```
sendAI({
  senderId: string,
  message: object | string,
  saveHistory?: boolean,   // default true
  sessionId?: string,      // omit on first turn; pass on follow-ups
  provider?: string,       // e.g. "open_ai" — optional override
  model?: string,          // e.g. "gpt-4o" — optional override
})
```

| Option        | Default         | Description                                                                        |
| ------------- | --------------- | ---------------------------------------------------------------------------------- |
| `senderId`    | —               | User id for the AI call                                                            |
| `message`     | —               | Prompt payload (`text`, `messages`, RAG flags, …)                                  |
| `saveHistory` | `true`          | Persist turn to AI history                                                         |
| `sessionId`   | new UUID        | Continue an existing session                                                       |
| `provider`    | project default | Merged into request `data` when set                                                |
| `model`       | project default | Merged into request `data` when set; also recorded in session logs / observability |

When `provider` / `model` are omitted, you get the project default from auth (`current_model`). Agents can carry their own defaults via `defineAgent({ provider, model })`; a value on the `sendAI` call still wins.

Provider API keys and cloud endpoints are set in the [portal](https://app.dnotifier.com), not in SDK code. Full list and walkthroughs: [Multi-model providers](/product-docs/ai/multi-models.md).

```js
await notifier.sendAI({
  senderId: USER_ID,
  provider: "open_ai",
  model: "gpt-4o",
  message: {
    useKnowledgeBase: false,
    messages: [{ role: "user", content: "Reply with exactly one word: ok" }],
  },
});
```

Supported `provider` strings (and deeper pages): [multi-models README](/product-docs/ai/multi-models.md).

## Response handling

HTTP `sendAI` resolves with the server response object. Extract the assistant text from common fields:

```js
function extractContent(response) {
  return (
    response?.data?.content ??
    response?.content ??
    (typeof response === "string" ? response : JSON.stringify(response))
  );
}
```

Session id for continuation (first turn):

```js
const sessionId =
  response?.metadata?.packet?.id ??
  response?.metadata?.id;
```

## Language guides

| Language                | Guide                                                                             |
| ----------------------- | --------------------------------------------------------------------------------- |
| JavaScript / TypeScript | [javascript-typescript.md](/product-docs/ai/send-prompt/javascript-typescript.md) |
| Dart / Flutter          | [dart-flutter.md](/product-docs/ai/send-prompt/dart-flutter.md)                   |

## Error handling

| Error                | Likely cause                           |
| -------------------- | -------------------------------------- |
| `Not connected`      | Call `connect()` first                 |
| `senderId required`  | Pass `senderId` matching your user     |
| `AI is not enabled`  | Upgrade plan or enable AI in dashboard |
| `null` response (JS) | Network or server error — check logs   |

## Next steps

* [Multi-model providers](/product-docs/ai/multi-models.md) if you need a specific vendor / model
* [Chat-style messages](/product-docs/ai/chat-style-messages.md) for `messages[]` and RAG flags
* [Sessions](/product-docs/ai/sessions.md) when you need `sessionId`
* [Session logging](/product-docs/ai/session-logging.md) for dashboard logs (`logs: true`)
