---
title: "Getting started with AI Assistant and Nutrient Web SDK"
canonical_url: "https://www.nutrient.io/sdk/ai-assistant/getting-started/web/"
md_url: "https://www.nutrient.io/sdk/ai-assistant/getting-started/web.md"
last_updated: "2026-05-30T02:20:01.489Z"
description: "Integrate AI Assistant with Nutrient Web SDK for powerful document processing. Enable document querying, summarizing, and translation in your applications."
---

# Getting started with AI Assistant and Nutrient Web SDK

AI Assistant provides [Nutrient Web SDK](https://www.nutrient.io/guides/web.md) with AI functionality. Using intelligent document processing (IDP) technology, AI Assistant enables users to query, summarize, translate, compare document text on the fly.

**View example**

Prefer to jump straight into code? View the example repo on GitHub.

[Read more](https://github.com/PSPDFKit/ai-assistant-demo)

To set up a fully functional AI system, you’ll need a Docker container service and a library working in unison:

- [Nutrient Web SDK](https://www.nutrient.io/guides/web.md) — A document viewer in the browser that also exposes a user interface (UI) for the AI features.

- AI Assistant — A service to process the AI requests and process documents.

This guide will walk you through the setup for AI Assistant. It’ll then walk you through a Node.js Nutrient Web SDK example to show how each service communicates to serve an AI example.

## Prerequisites

AI Assistant is distributed as a Docker container. To run it on your computer, you need to install a Docker runtime distribution for your operating system.

### macOS

Install and start Docker Desktop for Mac. Refer to the [Docker website](https://docs.docker.com/docker-for-mac/install/) for instructions.

### Windows

Install and start Docker Desktop for Windows. Refer to the [Docker website](https://docs.docker.com/docker-for-windows/install/) for instructions.

### Linux

Install and start Docker Engine. Refer to the [Docker website](https://docs.docker.com/engine/install/#server) for instructions on how to install it for your Linux distribution.

After you install Docker, use [these instructions](https://docs.docker.com/compose/install/#install-compose-on-linux-systems) to install Docker Compose.

## Obtaining an OpenAI API key

AI Assistant requires an API key from either of these LLM providers:

- OpenAI

- Azure OpenAI

This example will use OpenAI, but if you’d like to use Azure OpenAI, refer to the [Azure OpenAI guide](https://www.nutrient.io/guides/ai-assistant/service-configuration/model-providers/azure-provider.md).

If you don’t have an OpenAI key, create one by following the steps in the next section. Otherwise, skip to the [Setting up AI Assistant](#setting-up-ai-assistant) section.

### Creating an OpenAI account

To create an OpenAI account, [sign up](https://platform.openai.com/signup) to obtain an [API key](https://platform.openai.com/account/api-keys).

> The OpenAI API has attained **SOC 2 Type 2** compliance (see the [official announcement](https://trust.openai.com/?tcuUid=16a1f4e1-9120-45c1-96bd-5c1007f0f3d1)).

Save your API key somewhere safe, as you’ll need it in the [Setting up AI Assistant](#setting-up-ai-assistant) section.

## Setting up AI Assistant

AI Assistant requires a PostgreSQL database with the [pgvector](https://github.com/pgvector/pgvector) extension to operate.

Copy the code snippet below and save it anywhere on your computer in a file called `docker-compose.yml`. Replace the `<your-openai-api-key>` placeholder with your OpenAI API key:

```yaml

version: "3.8"

services:
  ai-assistant:
    image: pspdfkit/ai-assistant:nightly
    environment:
      OPENAI_API_KEY: <your-openai-api-key>
      PGUSER: db-user
      PGPASSWORD: password
      PGDATABASE: ai_assistant
      PGHOST: db
      PGPORT: 5432
      API_AUTH_TOKEN: secret
      JWT_PUBLIC_KEY: |
        -----BEGIN PUBLIC KEY-----
        MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2gzhmJ9TDanEzWdP1WG+
        0Ecwbe7f3bv6e5UUpvcT5q68IQJKP47AQdBAnSlFVi4X9SaurbWoXdS6jpmPpk24
        QvitzLNFphHdwjFBelTAOa6taZrSusoFvrtK9x5xsW4zzt/bkpUraNx82Z8MwLwr
        t6HlY7dgO9+xBAabj4t1d2t+0HS8O/ed3CB6T2lj6S8AbLDSEFc9ScO6Uc1XJlSo
        rgyJJSPCpNhSq3AubEZ1wMS1iEtgAzTPRDsQv50qWIbn634HLWxTP/UH6YNJBwzt
        3O6q29kTtjXlMGXCvin37PyX4Jy1IiPFwJm45aWJGKSfVGMDojTJbuUtM+8P9Rrn
        AwIDAQAB
        -----END PUBLIC KEY-----
      JWT_ALGORITHM: RS256
      DASHBOARD_USERNAME: dashboard
      DASHBOARD_PASSWORD: secret
      SECRET_KEY_BASE: secret-key-base
    ports:
      - 4000:4000
    depends_on:
      db:
        condition: service_healthy
  db:
    image: pgvector/pgvector:pg16
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U db-user -d ai_assistant" ]
      interval: 3s
      timeout: 3s
      retries: 10
    environment:
      POSTGRES_USER: db-user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: ai_assistant
      POSTGRES_INITDB_ARGS: --data-checksums
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

```

## Starting AI Assistant

Now open a terminal emulator.

### macOS

Use the terminal emulator integrated with your code editor or IDE. Alternatively, you can use `Terminal.app` or [iTerm2](https://iterm2.com/).

### Windows

Use your code editor’s integrated terminal or [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell?view=powershell-7.5).

### Linux

Use the terminal emulator integrated with your code editor or IDE, or one bundled with your desktop environment.

Go to the directory where you saved the `docker-compose.yml` file:

```sh

cd <path-to-directory-with-docker-compose-yml>

```

Run the following:

```sh

docker-compose up

```

This command might take a while to run, depending on your internet connection speed. Wait until you see the following message in the terminal:

```

ai_document_assistant  | info: AI Assistant started

```

AI Assistant is now up and running!

## Setting up Nutrient Web SDK

Follow the below instructions to set up Nutrient Web SDK viewer with AI Assistant.

### Installing Node.js

If you haven’t installed Node.js, head to [the official guides](https://nodejs.org/en/download/package-manager) and follow the instructions. By the end of the installation process, you should be able to run the following command:

```

node --version

```

The output should be something like v14. You can ignore any subsequent number.

### Generating the application

You’ll use [Express](https://expressjs.com/), one of the most common Node.js web frameworks. To create a new Express application, you can use the official generator.

Run:

```

npx express-generator pspdfkit_example --view=ejs

```

This command will generate a project structure and instruct you on the steps to follow to install dependencies and start the project.

Once you’ve followed all the steps, you should be able to visit http://localhost:3000 to confirm the application is working as expected.

## Configuring AI Assistant in Nutrient Web SDK

To configure Nutrient Web SDK to use AI Assistant:

- Generate a JSON Web Token (JWT) on the backend for AI Assistant communication

- Pass the AI Assistant configuration to [`PSPDFKit.load()`](https://www.nutrient.io/api/web/PSPDFKit.html#.load).

1. Create the document’s route in `./routes/documents.js`:

   ```js

     var express = require("express");
     var router = express.Router();

     router.get('/', function (_req, res, _next) {
     res.render('documents/show')
     })

    module.exports = router;
   ```

2. Create the AI Assistant JWT in `./routes/documents.js`:

   ```diff

    var express = require("express");
    var router = express.Router();
    + var fs = require("fs");
    + var path = require("path");
    + var jwt = require("jsonwebtoken");
    + var jwtKey = fs.readFileSync(
    +   path.resolve(__dirname, "../config/pspdfkit/jwt.pem")
    + );

    router.get("/", function (req, res, next) {
    +   var aiJwt = prepareAIDocumentAssistantJwt();
    -   res.render("documents/show");
    +   res.render("documents/show", { aiJwt: aiJwt });
      });
    +
    + const prepareAIDocumentAssistantJwt = function (documentId) {
    +   var claims = {}
    +
    +   return jwt.sign(claims, jwtKey, {
    +     algorithm: "RS256",
    +     expiresIn: 60 * 60, // 1hr, this will set the `exp` claim.
    +     allowInsecureKeySizes: true,
    +   });
    + }

    module.exports = router;
   ```

3. Create a corresponding view with some minimal HTML that loads the Nutrient library, uses the JWT created by the router in the previous step, and adds a toolbar item to activate AI Assistant in `/views/documents/show.ejs`:

   ```js

    <script src="https://cdn.cloud.nutrient.io/pspdfkit-web@1.15.1/pspdfkit.js"></script>
    <!-- 2. Element where PSPDFKit will be mounted. -->

    <div id="pspdfkit" style="width: 100%; max-width: 800px; height: 480px;"></div>
    <!-- 3. Initialize PSPDFKit. -->

    <script>
      PSPDFKit.load({
            document: "/samples/example.pdf",
            container: "#pspdfkit",

            instant: false,
            toolbarItems: [...PSPDFKit.defaultToolbarItems, { type: "ai-document-assistant" }],
            aiDocumentAssistant: {
                sessionId: "my-random-session-id",
                jwt: "<%%= aiJwt %>",
                backendUrl: 'http://localhost:4000/',
            },
      }).then(function(instance) {
        console.log("PSPDFKit loaded", instance);
       }).catch(function(error) {
       console.error(error.message);
      });
     </script>
   ```

Refresh the page, and you’ll see the Nutrient Web SDK viewer with a new AI toolbar button. Click that button and the chat dialog will open and the document processing mechanism will begin. Once the spinner has stopped spinning, you’ll be able to interact with AI Assistant!
---

## Related pages

- [Getting started with AI Assistant](/sdk/ai-assistant/getting-started.md)
- [Getting started with AI Assistant and Nutrient Android SDK](/sdk/ai-assistant/getting-started/android.md)
- [Getting started with AI Assistant and Nutrient iOS SDK](/sdk/ai-assistant/getting-started/ios.md)
- [Getting started with AI Assistant and Nutrient Web SDK + Document Engine](/sdk/ai-assistant/getting-started/document-engine.md)

