SDK ReferenceTypeScript SDK

Sessions

Usage

Access this class through the composio.sessions property:

const composio = new Composio({ apiKey: 'your-api-key' });
const result = await composio.sessions.list();

Methods

create()

Creates a new tool router session for a user. Use sessionPreset: SessionPreset.DIRECT_TOOLS when all needed tools should be exposed directly; see ToolRouterCreateSessionConfig.

Overload 1

async create(userId: string, config: object): Promise<Session<TToolCollection, TTool, TProvider>>

Parameters

NameTypeDescription
userIdstring{string} The user id to create the session for
configobject{ToolRouterCreateSessionConfig} The config for the tool router session

Returns

Promise<Session<TToolCollection, TTool, TProvider>> — The tool router session

Overload 2

async create(userId: string, config?: object): Promise<SessionWithoutMcp<TToolCollection, TTool, TProvider>>

Parameters

NameTypeDescription
userIdstring{string} The user id to create the session for
config?object{ToolRouterCreateSessionConfig} The config for the tool router session

Returns

Promise<SessionWithoutMcp<TToolCollection, TTool, TProvider>> — The tool router session

Example

import { Composio } from '@composio/core';

const composio = new Composio();

const session = await composio.sessions.create('user_123', {
  toolkits: ['gmail'],
  manageConnections: true,
  experimental: {
    customTools: [myCustomTool],
    customToolkits: [myToolkit],
  },
});

use()

Use an existing session

Overload 1

async use(id: string, options: { customToolkits?: CustomToolkit[]; customTools?: CustomTool[]; mcp: true }): Promise<Session<TToolCollection, TTool, TProvider>>

Parameters

NameTypeDescription
idstring{string} The id of the session to use
optionsobject

Returns

Promise<Session<TToolCollection, TTool, TProvider>> — The tool router session

Overload 2

async use(id: string, options?: { customToolkits?: CustomToolkit[]; customTools?: CustomTool[]; mcp?: boolean }): Promise<SessionWithoutMcp<TToolCollection, TTool, TProvider>>

Parameters

NameTypeDescription
idstring{string} The id of the session to use
options?object

Returns

Promise<SessionWithoutMcp<TToolCollection, TTool, TProvider>> — The tool router session

Example

import { Composio } from '@composio/core';

const composio = new Composio();
const id = 'session_123';
const session = await composio.sessions.use(id);

console.log(session.mcp.url);
console.log(session.mcp.headers);