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

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

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.

Description

enhancement
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.

Dominant language
TypeScript
Stars
2.5k
Forks
355
Avg merge
2d 15h
Merged PRs (30d)
42

Getting set up

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.

More from vercel/chat

All issues in vercel/chat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.