Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

manual auth fixes

Sushmithamallesh20d1f7b02811
diff --git a/fern/pages/src/tool-router/managing-multiple-accounts.mdx b/fern/pages/src/tool-router/managing-multiple-accounts.mdx
index 9266c36ff..812bf828c 100644
--- a/fern/pages/src/tool-router/managing-multiple-accounts.mdx
+++ b/fern/pages/src/tool-router/managing-multiple-accounts.mdx
@@ -1,52 +1,104 @@
---
-title: Managing multiple accounts for a user
+title: Managing multiple accounts
image: "https://og.composio.dev/api/og?title=Managing%20Multiple%20Accounts"
description: "Handle users with multiple accounts for the same toolkit"
keywords: "tool router, multiple accounts, connected accounts, account selection"
---
-Users can connect multiple accounts for the same toolkit (e.g., personal and work Gmail). Tool Router uses the most recently connected account by default.
+Users can connect multiple accounts for the same toolkit (e.g., personal and work Gmail accounts). This is useful when users need to manage different email accounts, GitHub organizations, or separate work and personal contexts. This guide explains how to connect, select, and manage multiple accounts.
-## Selecting a specific account
+## Default account behavior
-To use a specific account, pass it in the session config:
+When multiple accounts are connected for the same toolkit:
+- Tool Router uses the **most recently connected account** by default
+- You can override this by explicitly selecting an account
+- Each account maintains its own authentication and permissions
+
+## Connecting multiple accounts
+
+Call `session.authorize()` multiple times for the same toolkit. Each authorization creates a separate connected account with its own ID. The most recently connected account becomes the active one for that session. New sessions will also use the most recent account unless you [explicitly select a different one](#selecting-a-specific-account-for-a-session).
+
+<CodeGroup>
+```python
+session = composio.create(user_id="user_123")
+
+# Connect first account (work)
+work_auth = session.authorize("gmail")
+print(f"Connect work Gmail: {work_auth.redirect_url}")
+work_connection = work_auth.wait_for_connection()
+print(f"Work account connected: {work_connection.id}")
+
+# Connect second account (personal)
+personal_auth = session.authorize("gmail")
+print(f"Connect personal Gmail: {personal_auth.redirect_url}")
+personal_connection = personal_auth.wait_for_connection()
+print(f"Personal account connected: {personal_connection.id}")
+```
+```typescript
+const session = await composio.create("user_123");
+
+// Connect first account (work)
+const workAuth = await session.authorize("gmail");
+console.log(`Connect work Gmail: ${workAuth.redirectUrl}`);
+const workConnection = await workAuth.waitForConnection();
+console.log(`Work account connected: ${workConnection.id}`);
+
+// Connect second account (personal)
+const personalAuth = await session.authorize("gmail");
+console.log(`Connect personal Gmail: ${personalAuth.redirectUrl}`);
+const personalConnection = await personalAuth.waitForConnection();
+console.log(`Personal account connected: ${personalConnection.id}`);
+```
+</CodeGroup>
+
+<Note>
+Store the account IDs returned after connection to explicitly select accounts later.
+</Note>
+
+## Selecting a specific account for a session
+
+To use a specific account in a session, pass it in the session config:
<CodeGroup>
```python
session = composio.create(
- user_id=user_id,
+ user_id="user_123",
connected_accounts={
- "gmail": "ca_specific_account_id",
+ "gmail": "ca_specific_account_id", # Connected account ID
},
)
```
```typescript
-const session = await composio.create(userId, {
+const session = await composio.create("user_123", {
connectedAccounts: {
- gmail: "ca_specific_account_id",
+ gmail: "ca_specific_account_id", // Connected account ID
},
});
```
</CodeGroup>
-## Listing connected accounts
+## Listing all user accounts
+
+To list all accounts a user has connected (not just the active one), see [List accounts](/docs/connected-accounts#list-accounts) in the Connected Accounts guide.
+
+## Viewing session's active account
-Use `session.toolkits()` to see all connected accounts for a user:
+Use `session.toolkits()` to see which account is currently active in the session:
<CodeGroup>
```python
toolkits = session.toolkits()
-for toolkit in toolkits:
- if toolkit.connected_account:
- print(f"{toolkit.name}: {toolkit.connected_account.id}")
+for toolkit in toolkits.items:
+ if toolkit.connection.connected_account:
+ print(f"{toolkit.name}: {toolkit.connection.connected_account.id}")
```
```typescript
const toolkits = await session.toolkits();
-for (const toolkit of toolkits) {
- if (toolkit.connectedAccount) {
- console.log(`${toolkit.name}: ${toolkit.connectedAccount.id}`);
+for (const toolkit of toolkits.items) {
+ if (toolkit.connection.connectedAccount) {
+ console.log(`${toolkit.name}: ${toolkit.connection.connectedAccount.id}`);
}
}
```