Composio

@composio/core


@composio/core / composio / Composio

Class: Composio<TProvider>

Defined in: ts/packages/core/src/composio.ts:122

This is the core class for Composio. It is used to initialize the Composio SDK and provide a global configuration.

Type Parameters

TProvider

TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider

Constructors

Constructor

new Composio<TProvider>(config?): Composio<TProvider>

Defined in: ts/packages/core/src/composio.ts:228

Creates a new instance of the Composio SDK.

The constructor initializes the SDK with the provided configuration options, sets up the API client, and initializes all core models (tools, toolkits, etc.).

Parameters

config?

ComposioConfig<TProvider>

Configuration options for the Composio SDK

Returns

Composio<TProvider>

Example

1// Initialize with default configuration
2const composio = new Composio();
3
4// Initialize with custom API key and base URL
5const composio = new Composio({
6 apiKey: 'your-api-key',
7 baseURL: 'https://api.composio.dev'
8});
9
10// Initialize with custom provider
11const composio = new Composio({
12 apiKey: 'your-api-key',
13 provider: new CustomProvider()
14});

Properties

authConfigs

authConfigs: AuthConfigs

Defined in: ts/packages/core/src/composio.ts:152

Manage authentication configurations for toolkits


client

protected client: Composio

Defined in: ts/packages/core/src/composio.ts:129

The Composio API client.


connectedAccounts

connectedAccounts: ConnectedAccounts

Defined in: ts/packages/core/src/composio.ts:154

Manage authenticated connections


create()

create: (userId, routerConfig?) => Promise<ToolRouterSession<unknown, unknown, TProvider>>

Defined in: ts/packages/core/src/composio.ts:185

Creates a new tool router session for a user.

Parameters

userId

string

{string} The user id to create the session for

routerConfig?

Returns

Promise<ToolRouterSession<unknown, unknown, TProvider>>

The tool router session

Example

1import { Composio } from '@composio/core';
2
3const composio = new Composio();
4const userId = 'user_123';
5
6const session = await composio.create(userId, {
7 manageConnections: true,
8});
9
10console.log(session.sessionId);
11console.log(session.url);
12console.log(session.tools());

files

files: Files

Defined in: ts/packages/core/src/composio.ts:150

Upload and download files


mcp

mcp: MCP

Defined in: ts/packages/core/src/composio.ts:156

Model Context Protocol server management


provider

provider: TProvider

Defined in: ts/packages/core/src/composio.ts:148

The tool provider instance used for wrapping tools in framework-specific formats


toolkits

toolkits: Toolkits

Defined in: ts/packages/core/src/composio.ts:144

Retrieve toolkit metadata and authorize user connections


toolRouter

toolRouter: ToolRouter<unknown, unknown, TProvider>

Defined in: ts/packages/core/src/composio.ts:161

Experimental

Experimental feature, use with caution


tools

tools: Tools<unknown, unknown, TProvider>

Defined in: ts/packages/core/src/composio.ts:142

List, retrieve, and execute tools


triggers

triggers: Triggers<TProvider>

Defined in: ts/packages/core/src/composio.ts:146

Manage webhook triggers and event subscriptions


use()

use: (id) => Promise<ToolRouterSession<unknown, unknown, TProvider>>

Defined in: ts/packages/core/src/composio.ts:196

Use an existing tool router session

Parameters

id

string

{string} The id of the session to use

Returns

Promise<ToolRouterSession<unknown, unknown, TProvider>>

The tool router session

Methods

createSession()

createSession(options?): Composio<TProvider>

Defined in: ts/packages/core/src/composio.ts:367

Creates a new instance of the Composio SDK with custom request options while preserving the existing configuration. This method is particularly useful when you need to:

  • Add custom headers for specific requests
  • Track request contexts with unique identifiers
  • Override default request behavior for a subset of operations

The new instance inherits all configuration from the parent instance (apiKey, baseURL, provider, etc.) but allows you to specify custom request options that will be used for all API calls made through this session.

Parameters

options?
headers?

ComposioRequestHeaders

Returns

Composio<TProvider>

A new Composio instance with the custom request options applied.

Example

1// Create a base Composio instance
2const composio = new Composio({
3 apiKey: 'your-api-key'
4});
5
6// Create a session with request tracking headers
7const composioWithCustomHeaders = composio.createSession({
8 headers: {
9 'x-request-id': '1234567890',
10 'x-correlation-id': 'session-abc-123',
11 'x-custom-header': 'custom-value'
12 }
13});
14
15// Use the session for making API calls with the custom headers
16await composioWithCustomHeaders.tools.list();

flush()

flush(): Promise<void>

Defined in: ts/packages/core/src/composio.ts:402

Flush any pending telemetry and wait for it to complete.

In Node.js-compatible environments, telemetry is automatically flushed on process exit. However, in environments like Cloudflare Workers that don’t support process exit events, you should call this method manually to ensure all telemetry is sent.

Returns

Promise<void>

A promise that resolves when all pending telemetry has been sent.

Example

1// In a Cloudflare Worker, use ctx.waitUntil to ensure telemetry is flushed
2export default {
3 async fetch(request: Request, env: Env, ctx: ExecutionContext) {
4 const composio = new Composio({ apiKey: env.COMPOSIO_API_KEY });
5
6 // Do your work...
7 const result = await composio.tools.execute(...);
8
9 // Ensure telemetry flushes before worker terminates
10 ctx.waitUntil(composio.flush());
11
12 return new Response(JSON.stringify(result));
13 }
14};

getClient()

getClient(): Composio

Defined in: ts/packages/core/src/composio.ts:318

Get the Composio SDK client.

Returns

Composio

The Composio API client.


getConfig()

getConfig(): ComposioConfig<TProvider>

Defined in: ts/packages/core/src/composio.ts:329

Get the configuration SDK is initialized with

Returns

ComposioConfig<TProvider>

The configuration SDK is initialized with