> ## Documentation Index
> Fetch the complete documentation index at: https://metacognition-fdc534de-master.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Scopes and multi-tenancy

> Use org_id, user_id, and session_id to keep memory separated.

Every memory call is scoped by **`org_id`**, **`user_id`**, and **`session_id`**.

Your API key decides **`org_id`**. The SDK usually gets **`user_id`** from the token. Your app chooses **`session_id`**. That is the field you use for a chat thread, Slack channel, agent run, or tenant-specific memory.

| Field        | Source                                    | You set it?  |
| ------------ | ----------------------------------------- | ------------ |
| `org_id`     | JWT minted from your API key              | Almost never |
| `user_id`    | JWT (or per-call override when supported) | Sometimes    |
| `session_id` | Your application                          | **Always**   |

In most apps, **`session_id`** is the field you set on every call.

## `session_id`

Pick a stable pattern:

<CardGroup cols={2}>
  <Card title="Single chat thread" icon="message">
    `chat-{conversation_uuid}`
  </Card>

  <Card title="Slack channel" icon="hashtag">
    `slack-{channel_id}`
  </Card>

  <Card title="Agent run" icon="robot">
    `agent-{task_id}`
  </Card>

  <Card title="Long-lived user profile" icon="infinity">
    `bio-{user_id}`
  </Card>
</CardGroup>

Use the same string for the same logical thread. That way **`recall`** searches the same memory each time.

## SaaS (one key)

For a SaaS app, map each customer or user conversation to a distinct **`session_id`**. One shared **`Tex`** client is enough:

```python theme={null}
tex = Tex(api_key=os.environ["TEX_API_KEY"], base_url=BASE_URL)

def chat(user_msg: str, x_user_id: str, conv_id: str):
    sid = f"u_{x_user_id}-{conv_id}"
    hits = tex.recall(q=user_msg, session_id=sid)
    ...
```

That gives you one bill and separated memory. The only rule is simple: never reuse one customer's **`session_id`** for another customer.

<Note>
  Per-call `user_id` overrides are planned for **SDK 1.2**. Until then, include the end user in `session_id`. The [multi-tenant SaaS recipe](/recipes/multi-tenant-saas) shows the full pattern.
</Note>

<Card title="Recall and ranking" icon="magnifying-glass" href="/concepts/retrieval" horizontal>
  `top_k`, modes, confidence.
</Card>
