Skip to main content

Connected Accounts

Connected accounts represent authenticated user connections to third-party services. They store credentials and authentication state, enabling users to execute tools on external platforms like GitHub, Slack, or Gmail.

Overview

The ConnectedAccounts class manages user authentication and connections to external services in the Composio SDK. Each connected account links a user to a specific toolkit through an authentication configuration. Source: ts/packages/core/src/models/ConnectedAccounts.ts

Creating Connected Accounts

Initiate a Connection

The initiate method creates a new connected account and returns a connection request:
By default, initiate prevents creating multiple connected accounts for the same user and auth config. Set allowMultiple: true in options to override this behavior.
Generate an external link for users to authenticate:

Wait for Connection

Poll for connection completion:
The waitForConnection method continuously polls the API until the connection becomes active, fails, or times out. Terminal states include: ACTIVE, FAILED, EXPIRED, and DELETED.

Listing Connected Accounts

List All Connected Accounts

Filter by User

Filter by Toolkit

Filter by Status

Combine Filters

Pagination

Retrieving a Connected Account

Get detailed information about a specific connected account:

Managing Connected Accounts

Refresh Credentials

Refresh OAuth tokens or other credentials:
Refreshing credentials is useful when OAuth tokens expire. The SDK will attempt to use the refresh token to obtain new access tokens.

Enable/Disable Accounts

Update Account Status

Update with additional context:

Delete a Connected Account

Deleting a connected account is permanent and cannot be undone. It will revoke any access tokens associated with the account.

Connected Account Properties

Every connected account object contains:
  • id - Unique identifier for the connected account
  • userId - The external user ID
  • status - Current status (INITIATED, ACTIVE, FAILED, EXPIRED, DELETED)
  • toolkit - Information about the connected toolkit
  • authConfig - Authentication configuration details
  • state - Authentication state and credentials (encrypted)
  • isDisabled - Whether the account is disabled
  • createdAt - When the account was created
  • updatedAt - When the account was last updated

Connection Status

Possible status values:
  • INITIATED - Connection process started, waiting for user authentication
  • ACTIVE - Successfully connected and authenticated
  • FAILED - Authentication failed
  • EXPIRED - Connection expired (credentials no longer valid)
  • DELETED - Connection was deleted

Complete Connection Flow Example

Multiple Accounts Per User

Allow users to connect multiple accounts for the same service:
When allowMultiple is true, the SDK will allow creating multiple connected accounts for the same user and auth config combination. This is useful when users need to manage multiple GitHub organizations or Slack workspaces.

Error Handling

Common errors when working with connected accounts:
  • ComposioConnectedAccountNotFoundError - Connected account doesn’t exist
  • ComposioMultipleConnectedAccountsError - Multiple accounts exist and allowMultiple is false
  • ComposioFailedToCreateConnectedAccountLink - Failed to create connection link
  • ConnectionRequestFailedError - Connection entered a failed state
  • ConnectionRequestTimeoutError - Connection didn’t complete within timeout
  • ValidationError - Invalid parameters passed to methods

Example Error Handling

  • Authentication - Configure authentication methods
  • Toolkits - Services that connected accounts authenticate with
  • Tools - Execute tools using connected accounts
  • Providers - Use connected accounts with AI frameworks