Picture the concierge desk in a large apartment building. Behind the desk is a cabinet with a key for every flat. A guest arrives, says who they are visiting, and the concierge checks, takes that one key, and lets them into that one flat. The guest never holds the key, never sees the cabinet, and never gets into the flat next door, however politely they ask.
If you are a software company whose product gives each of your customers their own AI employees on Wetel, your backend is that concierge. This post walks through the pattern our docs call the gateway pattern: how it works, what reaches the browser, the mistakes that undo it, and what it does not give you.
The short answer
Give each of your customers their own Wetel workspace and their own API key, keep every key on your server, and let your backend start each conversation with the right customer’s key. Wetel returns a short-lived session token for that one conversation, and only that token goes to the end user’s browser. From then on, each conversation works exactly like a single-customer integration.
Wetel keeps workspaces apart on every request, so your frontend code needs no special multi-customer logic. The separation that matters, which customer’s key to use for which end user, lives in one place: your backend.
Each customer’s AI employees are still set up and supervised by people: your team, theirs, or both, signed in to that customer’s workspace. The gateway only starts conversations; it does not change how anyone works.
Why one workspace per customer?
Because the workspace is the unit Wetel keeps separate. Every account belongs to exactly one workspace (the API calls it a tenant). Its AI employees, workflows, tools, knowledge bases, conversations, users and API keys are kept separate from every other workspace’s: each request is scoped to the workspace of the signed-in person or the key, and every query filters by it. A request made for one workspace cannot see or change another’s data, whatever record numbers someone guesses.
The API itself is identical for every workspace. Your gateway calls the same operations for customer A and customer B; only the key differs, and the key decides whose data is behind the call.
That means the model is one workspace per customer. If two of your customers shared one workspace, they would share everything in it.
How does the gateway pattern work?
Your frontend asks your backend, your backend picks the customer’s key and starts the conversation, and the browser gets back only a conversation id and a session token.
sequenceDiagram participant B as End user's browser participant G as Your backend (gateway) participant S as Your key store participant W as Wetel
B->>G: start a chat for customer 123 G->>G: check this user belongs to customer 123 G->>S: fetch customer 123's API key S-->>G: key (stays on the server) G->>W: sdkStart(agentId) with that key W-->>G: sessionId + short-lived session token G-->>B: sessionId + session token B->>W: subscribe to replies, send messages (session token) W-->>B: replies arrive as eventsStep by step:
- Each customer gets a workspace and a key. The key is created by someone signed in to that customer’s workspace: the customer themselves, or you, if you provision it for them. It is shown exactly once, and Wetel keeps only a fingerprint of it, so store it the moment it appears.
- Your backend stores every key server-side, in your own database or secrets manager, against your own customer id. Use a named key per customer (and per environment), so each one can be revoked on its own.
- An end user opens a chat. Your frontend calls your own backend, not Wetel, and sends your own customer id.
- Your backend checks and looks up. It confirms the signed-in end user really belongs to that customer (this check is yours; Wetel cannot know your users), then fetches that customer’s key.
- Your backend calls
sdkStartwith that key, addressed to that customer’s AI employee. The key can only start conversations with AI employees in its own workspace. - Wetel returns a
sessionIdand a session token, scoped to that one conversation in that one workspace. Your backend passes both to the browser. - From here it is a standard integration. The browser opens the reply subscription and sends messages with the session token. Sending a message returns an acknowledgement; the AI employee’s reply arrives as events on the subscription.
What reaches the browser, and what never does?
The browser holds a conversation id and a short-lived token for that one conversation. No customer’s long-lived key ever leaves your server, however many customers you serve.
The session token can send messages, end its conversation and receive its replies, for that one conversation only. It is short-lived on purpose, so a token seen in browser developer tools has little reach.
A long conversation does not need a new session. The browser (or your backend) can renew the token in place with refreshAvatarToken, on the same conversation. The renewal call accepts a token that expired within the last 10 minutes (a configurable default), so the natural pattern works: call, get an expired-token error, renew, retry. Two details to get right:
- Reopen the reply subscription after renewing. An open subscription reads its token once, when it connects, and cannot take a new one. If you renew and keep the old socket, your messages start working again while replies quietly stop arriving.
- A renewed token can never move. It carries the same conversation and the same workspace as the one it replaces, and only renews a conversation that is still active.
A variation: keep the browser away from Wetel entirely
Your backend can also hold the reply subscription itself and relay replies to the browser over your own channel, so the browser never sees a session token or a Wetel address at all. The docs call this the backend-proxied relay. It is not more secure than the default once the key is server-side in both; it is a trade-off.
Choose it if you want to moderate or log replies before delivery, keep your own copy of conversations as they pass through, or manage reconnection in one place. In exchange, your backend becomes a required hop for every message, and you take on routing replies to the right browser when you run more than one server. Wetel does not replay events a dropped subscription missed, so you need your own reconnect handling. And the relay does not save anything by itself: if you want your own copy of conversations, you write it.
What not to do
Never hand a customer’s API key to that customer’s frontend, and never share one key across customers.
- “It’s only their own workspace” is not a reason to send the key to a browser. A key is long-lived and works for anyone who holds it. Treat it like a database password: it lives in your backend only.
- One key for several customers defeats the whole pattern. A shared key means a shared workspace, so a bug or a leak on one customer’s integration can reach another customer’s data. One customer, one workspace, one key.
- Do not skip your own check in step 4. Wetel keeps workspaces apart, but it trusts the key you send. If your backend picks the wrong customer’s key for an end user, Wetel will correctly serve that customer’s workspace to the wrong person. Mapping users to customers is your gateway’s job.
Operational notes
Rate limits are counted per calling address, so all your customers share your server’s allowance. Every limited operation is counted by the address the request comes from, not by key or workspace, with one exception. When all your customers’ conversations start from one backend, they all draw on one count. Starting a conversation (sdkStart) defaults to 30 a minute per address, and an environment can be tuned differently; the limit that applies to you is the one in the error you get back. Direct text generation (generateText) is the one exception: it also has its own ceiling per workspace, and both must pass.
Some operations, including sending a message and ending a conversation, have no enforced limit today. The docs are clear that this is a current state, not a promise, so build your own backoff and retry, and add your own per-customer fairness limit in front if one noisy customer should not slow the rest.
Spending limits are per workspace. Each customer’s workspace has its own monthly language-model spend cap, set by its plan. It is checked before each conversation turn, workflow task and direct model call starts, and new work is refused until the month rolls over or the plan changes. It is a check made before work starts, not an exact meter: work already under way can go past it. Usage is reported per workspace, not per key, so per-customer reporting follows naturally from one workspace per customer.
Browser origins must be allowed. If browsers talk to Wetel directly (the default flow), each origin your customers’ frontends are served from must be on Wetel’s allow-list, or the browser will refuse to connect even with a valid token. Arrange this before go-live. With the relay variation, only your backend talks to Wetel.
What this pattern does not give you
Being plain about the limits:
- One workspace per customer is the model. Separation happens at the workspace, so different customers belong in different workspaces.
- No dedicated database option today. Workspaces share the platform’s database and are kept apart on every request. A dedicated database per workspace is designed but not offered.
- No third-party security certification yet. If your customers’ procurement asks, say so.
- Keys are revoked one at a time. Revoking a named key is immediate and permanent, for that key only. Rotation across many customers is something your gateway does key by key.
- Dashboard logins cannot be revoked early. They expire after about a day, so keep them out of long-running server processes and use API keys there.
- No replay of missed reply events, in either the default flow or the relay.
None of this changes the core guarantee: a request for one workspace cannot reach another’s data. The gateway makes sure each end user is sent to the right workspace in the first place, and that the keys stay behind the desk.
Related reference docs
- Multi-tenancy: the one-workspace-per-customer model and the gateway pattern, with its own sequence diagram
- Authentication: the three credentials, named keys, renewing a session token and revocation
- Core API Flow: starting a conversation, sending messages, receiving replies and ending it
- Backend-Proxied Relay Architecture: holding the reply subscription on your server instead
- Rate Limiting: why limits are counted per calling address, and which operations have none
- Pricing & Plans: the per-workspace spend cap and what it does and does not cover
- How are API keys scoped, and what can a key do?: the short answer on keys
If you are building this into your own product, tell us which work you’d hand over first and we will walk through the gateway with you.