Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ComposioHQ/composio/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through installing Composio, initializing the client, fetching tools from a toolkit, and running a real AI agent that uses those tools. By the end you will have a working agent that can query the HackerNews API through Composio.
Set COMPOSIO_API_KEY as an environment variable before you start. The SDK reads it automatically so you never have to hard-code credentials in your source files.
1

Install the SDK

Install the core Composio package plus the provider adapter for your AI framework. The examples below use OpenAI.
npm install @composio/core @composio/openai openai
2

Set your API key

Get your API key from the Composio dashboard and export it as an environment variable.
export COMPOSIO_API_KEY=your_api_key_here
The SDK automatically reads COMPOSIO_API_KEY from the environment, so you can also set it in a .env file for local development.
3

Initialize the client

Create a Composio instance. If COMPOSIO_API_KEY is set in the environment, you can omit the apiKey option entirely.
import { Composio } from '@composio/core';

const composio = new Composio({
  apiKey: process.env.COMPOSIO_API_KEY,
});
4

Get tools from a toolkit

Fetch the tools for a specific user and toolkit. The tools are automatically wrapped in the format your AI framework expects — no manual schema conversion required.
import { Composio } from '@composio/core';

const composio = new Composio({
  apiKey: process.env.COMPOSIO_API_KEY,
});

// Fetch HackerNews tools for this user
const tools = await composio.tools.get('user@example.com', {
  toolkits: ['HACKERNEWS'],
});

console.log(`Loaded ${tools.length} tools`);
The user_id / first argument scopes tool execution to a specific user’s connected accounts. Use a stable identifier like a database UUID in production — avoid "default" outside of experimentation.
5

Run an agent

Pass the tools directly to your AI framework. Composio handles tool execution automatically when the model calls a tool.
import { Composio } from '@composio/core';
import { OpenAI } from 'openai';

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const composio = new Composio({ apiKey: process.env.COMPOSIO_API_KEY });

const userId = 'user@example.com';

// Fetch tools for the user
const tools = await composio.tools.get(userId, {
  toolkits: ['HACKERNEWS'],
});

// First model call — ask the model to pick and call a tool
const response = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: "What is the latest HackerNews post about?" },
  ],
  tools: tools,
  tool_choice: 'auto',
});

// Execute any tool calls the model requested and get the final response
const result = await composio.provider.handleToolCalls(userId, response);
console.log(result);
The examples above use OpenAI. Composio supports many other AI frameworks with dedicated provider adapters — see Providers for the full list and setup instructions.

Build docs developers (and LLMs) love