vercel / vercel/chat

First-class multi-tenant runtime for per-connection bots

Open
#563 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
2.4k
Forks
314
Avg merge
1d 18h
Merged PRs (30d)
63

Description

Problem Statement

The Chat SDK assumes one bot identity and one credential set per process. In a SaaS product, each customer connects their own Telegram bot, SMS number, or WhatsApp sender. We need many isolated bot runtimes on shared webhook routes without running one process per connection.

Proposed Solution

Add a built-in multi-tenant mode (or official helper) that:

  1. Resolves a connection from platform + connectionKey on each webhook
  2. Lazily creates a Chat instance per connection with its own adapter credentials
  3. Prefixes shared state keys so thread/subscription state does not collide
  4. Exposes connection context in message handlers (e.g. via AsyncLocalStorage)
  5. Caches runtimes with LRU eviction

Handlers would receive (ctx, thread, message) where ctx.connection identifies the tenant.

Alternatives Considered
  • One global Chat and swap credentials per request: not safe for concurrent webhooks
  • One Chat singleton per connection: too much memory at scale
  • External wrapper package: works today, but belongs in the SDK long term

We ship option 3 as @delphi-ai/multi-tenant-chat until upstream support exists.

Use Case

Priority

Critical

Contribution
  • I am willing to help implement this feature
Additional Context

We already built and use this pattern. Reference implementation: https://github.com/delphi-ai/multi-tenant-chat.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the reference implementation at github.com/delphi-ai/multi-tenant-chat and comparing it with the SDK's webhook and Chat runtime entry points. The work is complete when connections resolve per webhook, runtimes isolate credentials and state, handlers receive connection context, and LRU eviction is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.