Run Lelemon for your customers with subaccounts
You sell a service built on Lelemon. Each of your customers gets a subaccount: its own agents, pipelines, cases, numbers and keys, isolated from the rest. You keep the tools in one place and share them with every subaccount, you fix how many conversations each one may have, and a single webhook endpoint tells you what happens in all of them.
Who it is for. Software platforms, agencies and franchisors that run agents for many customers. Scopes. Listed above. A subaccount key cannot exceed the scopes of the key that creates it.
- When your customer signs up, create the subaccount with your own id as externalRef and an Idempotency-Key.
- Lelemon answers with the sub_ id. A second subaccount with the same externalRef is a 409 external_ref_conflict.
- Any /v2 route acts on the subaccount when you add the header. The key does not change, only the organization.
- A subaccount is a full organization, isolated from your other subaccounts. One that is not yours answers 404.
- You create a tool once in your organization and share it. Each subaccount grants it to its own agents.
- When an agent of a subaccount uses the shared tool, your backend receives a call signed with your secret and Lelemon-Subaccount-Id, so it knows which customer is asking.
- One webhook endpoint with scope customers receives the events of all subaccounts. Each carries customerId, the sub_ id it belongs to.
Code
The script is in examples/use-cases/platform-subaccounts.
0. Set up
Code
1. Share an action with every subaccount
Create the action once with sharedWithSubaccounts: true. Your endpoint is yours: a variable of Lelemon (subaccount.id) tells it which customer is asking, and Lelemon fills it, not the model. A floor is the least approval any subaccount can run the action with; a subaccount can be stricter, never looser.
Code
2. Share an MCP server
Connect an MCP server of yours once. Its tools become available to every subaccount agent, with the credentials kept on your side.
Code
The server must be a public Streamable HTTP MCP server. The call asks it for its tools right away. See Actions and MCP.
3. Create a subaccount per customer
externalRef is your own id for the customer, so you can find the subaccount from your database.
Code
To give the customer direct access, POST /v2/subaccounts/{id}/api-keys issues a key that sees only that subaccount. See Run Lelemon for your customers.
4. Provision the subaccount and use the shared tools
Any route acts on a subaccount when you send the Lelemon-Subaccount header; the SDK does it with withSubaccount. Create the agent and the pipeline of the customer with the same instructions you use for everyone. The shared tools show up in the tool list of the agent with sharedByPlatform: true; grant the ones the customer needs.
Code
The subaccount does not list shared actions in GET /v2/actions: it reaches them through the tools of its agent, and cannot change or delete them.
5. Cap the conversations of a subaccount
A budget caps the conversations per month of the organization, a subaccount, an agent or a contact. With enforcement: "stop", a message that would open a conversation past the limit answers 402 budget_exceeded and the agent stops opening conversations until the month resets. At alertPercent the event budget.threshold_reached fires once.
Code
6. Receive the events of every subaccount
An endpoint with scope: "customers" receives the events of all your subaccounts; each one carries customerId, the sub_ id it belongs to. With scope: "self" it receives only those of the platform organization.
Code
7. Read the usage of all subaccounts
Bill your customers from the usage: turns, messages and tokens per day, agent, model or subaccount.
Notes
- A budget goes away with
DELETE /v2/budgets/{id}, andPATCH /v2/budgets/{id}changes its limit.
What you see in the dashboard
- Subaccounts: one per customer, with its agents, cases and keys, and the budget with its state (
ok,alert,limit_reached). - Actions and MCP servers: the shared ones marked as shared by the platform.
- Usage: the consumption by subaccount for the month.
What's next
- Run Lelemon for your customers: direct keys, templates and limits.
- Track usage and cap conversations.
- Approve agent actions: the floor in action.