> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flowra.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-tenant basics

> Use x-username so each end user gets isolated connected accounts and runs.

**Goal:** Link Slack (or another toolkit) for two different end users without mixing tokens.

In the dashboard, the same idea is the **End user** switcher — see [External users switcher](/product/external-users). On the API, you pass that identity as **`x-username`**. With the SDK, use `asUser` / `as_user` or the `username` constructor option.

## Prerequisites

* API key for your project — [Authentication](/authentication)
* An auth config for the toolkit — [Auth configs](/guides/auth-configs)

## Steps

<Steps>
  <Step title="Pick stable usernames">
    Choose one username per end user in your product (for example `customer_alice`, `customer_bob`). Use the **same string every time** for that person — in `x-username`, when you create them in the dashboard, and when you link accounts.
  </Step>

  <Step title="Link for alice">
    <CodeGroup>
      ```bash theme={null}
      curl -X POST "https://flowra.dev/api/v1/connected_accounts/link" \
        -H "x-api-key: YOUR_API_KEY" \
        -H "x-username: customer_alice" \
        -H "Content-Type: application/json" \
        -d '{
          "toolkitSlug": "slack",
          "authConfigId": "YOUR_AUTH_CONFIG_ID"
        }'
      ```

      ```ts theme={null}
      import { Flowra } from '@flowra/sdk';

      const flowra = new Flowra({ apiKey: process.env.FLOWRA_API_KEY! });
      const alice = flowra.asUser('customer_alice');
      await alice.connections.createLink({
        toolkitSlug: 'slack',
        authConfigId: 'YOUR_AUTH_CONFIG_ID',
      });
      ```

      ```python theme={null}
      from flowra import Flowra

      flowra = Flowra(api_key="YOUR_API_KEY")
      alice = flowra.as_user("customer_alice")
      alice.connections.create_link({
          "toolkitSlug": "slack",
          "authConfigId": "YOUR_AUTH_CONFIG_ID",
      })
      ```
    </CodeGroup>

    The response includes an OAuth **URL**. Open it in a browser, approve access as Alice’s Slack workspace, then return to your app. If `customer_alice` did not exist yet, Flowra creates that external user.
  </Step>

  <Step title="Link for bob">
    Same call with `customer_bob` (curl `x-username`, or `asUser('customer_bob')` / `as_user("customer_bob")`). Complete OAuth with **Bob’s** Slack workspace.
  </Step>

  <Step title="Run in the right context">
    When you execute a workflow or tool for Alice, always send `x-username: customer_alice` (or use the scoped SDK client). Omit the header only when you intentionally want the **project default** user.

    The same header also scopes [Knowledge](/guides/knowledge) and [Table](/guides/table) collections per end user — not only Slack connections.
  </Step>
</Steps>

## Verify

* List connected accounts once for alice and once for bob — each list should show that user’s Slack link, not the other’s.
* Or in the dashboard: switch **End user** to each username under [Connection](https://flowra.dev/dashboard/connection) and confirm separate rows.
* Execute a Slack-backed tool or workflow for Alice; confirm Bob’s workspace is never used.

## Next

* Full model and scoping matrix: [Multi-tenancy](/guides/multi-tenancy)
* Dashboard switcher: [External users switcher](/product/external-users)
* [Connect an account](/recipes/connect-an-account)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.