Where should I host a TypeScript AI assistant that saves conversations in Postgres?
A useful assistant needs to remember what the customer sees after a refresh or a return visit. Keeping an array in the server process or rendering model tokens in the browser does not give the app durable conversation history.
We make Prisma Compute and Prisma Postgres. The host documentation linked below was checked on October 18, 2026. Prisma ORM is optional, and the database model here does not depend on a particular model API.
What belongs on the server and in Postgres?
For chat between users, use the realtime chat database guide to compare durable messages, room permissions, presence and delivery after a reconnect.
The server authenticates the user, checks conversation access, calls the model provider and writes messages. Keep the model API key and database credentials in server-side configuration. The browser should call an application endpoint rather than connect with a database password.
Store conversations with an owner or account identifier. Store messages with a conversation reference, role, content and processing state. A request identifier helps the server recognize a retried send instead of creating another copy of the user's message.
Keep persistence separate from the model's context window. You can retain a conversation in Postgres while sending only selected messages or a summary to the model. Decide retention and deletion behavior for customer conversations before the app starts collecting sensitive text.
To add a rating to a saved answer, use the assistant feedback storage guide. It covers one vote per user and message, ownership checks and repeat submissions.
Which hosting setup fits the assistant?
These options are ordered alphabetically by app host.
| App host | When to choose it | Database and response work |
|---|---|---|
| Netlify + Prisma Postgres | Your framework already uses Netlify's deployment workflow. | Deploy the server features too, set the database URL in server configuration and check the runtime limits for your model calls. |
| Prisma Compute + Prisma Postgres | You want the TypeScript server and database declared in one project. | Configure the Composer module, database dependency and model API secret. Check request and streaming behavior. |
| Vercel + Prisma Postgres | Your app already follows Vercel's framework workflow. | Its streaming function documentation explains response delivery; the app must still save conversation data. |
Place the database-calling server near Postgres. Changing app hosts is optional: Prisma Postgres accepts ordinary PostgreSQL connections from a supported server runtime.
How do I connect and verify an existing assistant?
Use this database design and deployment checklist alongside the framework-specific deployment guide for your existing assistant. The SQL checks persistence; the app still needs its authenticated endpoints and model integration.
1. Choose one database creation workflow
Follow the Prisma Compute deployment guide for your framework and declare its services in a Prisma Composer module. If the module provisions the database, use the Composer database dependency instructions. For a dependency named db, the server gets its connection from service.load().db.url.
If the database already exists, configure its URL as a server-side input instead of provisioning a second one. Configure the model provider's API key as a separate secret input as well. Use a test database for migrations and assistant-driven changes.
2. Model conversations and messages
Run this SQL in a fresh development database through its direct connection, then adapt the schema into your migration workflow. The account ID is illustrative; a real app should connect it to the authenticated account model.
CREATE TABLE conversation_history_demo (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
account_id bigint NOT NULL,
title text NOT NULL
);
CREATE TABLE conversation_message_demo (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
conversation_id bigint NOT NULL
REFERENCES conversation_history_demo(id) ON DELETE CASCADE,
request_key text NOT NULL,
role text NOT NULL CHECK (role IN ('user', 'assistant')),
state text NOT NULL DEFAULT 'completed'
CHECK (state IN ('pending', 'completed', 'failed')),
content text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (conversation_id, request_key)
);
CREATE INDEX conversation_message_demo_history
ON conversation_message_demo (conversation_id, id);
INSERT INTO conversation_history_demo (account_id, title)
VALUES (42, 'Delivery question');
INSERT INTO conversation_message_demo
(conversation_id, request_key, role, content)
VALUES
(1, 'send-demo-1', 'user', 'When will my order arrive?'),
(1, 'reply-demo-1', 'assistant', 'I can help check the delivery details.');3. Read history through an authorized endpoint
The demonstration account is 42. This query joins the conversation's ownership to its messages:
SELECT id, role, state, content
FROM (
SELECT m.id, m.role, m.state, m.content
FROM conversation_message_demo m
JOIN conversation_history_demo c ON c.id = m.conversation_id
WHERE c.id = 1 AND c.account_id = 42
ORDER BY m.id DESC
LIMIT 50
) AS recent_messages
ORDER BY id;The inner query selects the latest 50 messages; the outer query puts that page in display order. For the two demonstration messages, it returns the user question followed by the assistant reply, with their IDs. In the server, bind query values as parameters and derive the authorized account from the verified session. Apply that check to writes and deletes too. If you use row-level security, configure the relevant roles and policies as well.
Use the smallest returned message ID as the cursor when requesting an older page. The demonstration page starts at ID 1, so this next-page query correctly returns no older rows:
SELECT id, role, state, content
FROM (
SELECT m.id, m.role, m.state, m.content
FROM conversation_message_demo m
JOIN conversation_history_demo c ON c.id = m.conversation_id
WHERE c.id = 1 AND c.account_id = 42 AND m.id < 1
ORDER BY m.id DESC
LIMIT 50
) AS older_messages
ORDER BY id;The application should bind the conversation, verified account and cursor as parameters. A new conversation loads the first query without a cursor; subsequent requests use the smallest ID from the previous page. If parallel generations need a strict conversational turn sequence, model that sequence explicitly; an insertion ID alone does not define the order in which concurrent work completes.
4. Define generation and interruption states
Save the user message before calling the model. Create an assistant message in pending state, then save its content and mark it completed when generation succeeds. Use distinct request keys for the user message and assistant reply, with duplicate-request handling in the server.
Decide how interrupted work becomes failed or resumes. Persist a start time or job identifier if you need a recovery process to find abandoned pending messages after a crash. Catching errors in a handler alone cannot update a row after the process has stopped.
For token-level resumption, persist chunks or events before relying on them as durable history. The Open Chat walkthrough describes an event-log design with Prisma Streams. Saving only the final response has a smaller implementation, but loses unsaved output if generation is interrupted.
5. Deploy and test a return visit
For a project with a build script and the module.ts prepared in step 1, authenticate, build the app and deploy a separate review stage. Configure the project region through the deployment setup if it is not already set. These commands use the current Prisma 8 release candidate CLI explicitly, so an older project-local CLI is not selected:
npx prisma@latest auth login
npm run build
npx prisma@latest deploy --stage assistant-reviewOpen the service URL returned by the deployment. Confirm that its database target is the intended review resource before applying migrations or testing writes. An externally supplied URL must point to a separate test database; changing the stage name does not isolate an external database by itself.
Prisma Compute runs deployed services on Bun, so check runtime-dependent packages. Its request timeout gives a service 60 seconds to start responding; a response that has started streaming is not subject to that first-byte deadline.
Test a saved conversation after refreshing, signing out and signing back in. Verify that another account cannot read its messages. Interrupt a generation and check that the UI and database state match the recovery behavior you chose. Also rehearse deleting a conversation and its associated messages.
When should I choose a different setup?
Prisma Compute currently does not host WebSocket servers. Use an HTTP streaming design it supports, or choose another app host if WebSocket server support is a requirement. Streaming an HTTP response also does not guarantee that an in-process generation job survives a restart or deployment.
Choose database hosting with the regions, extensions and recovery features your customer data requires. Prisma Postgres has plan-dependent snapshots and no point-in-time recovery yet (it is coming in November 2026). Keep long-term history, backups and model-provider costs as separate decisions when estimating the app's operating budget.
Frequently asked questions
Host the assistant and its conversation database together
Deploy the TypeScript server on Prisma Compute with Prisma Postgres, then test history and interruption behavior before inviting customers.