Skip to main content

Composio Integration Guide

APIpieComposio

This guide will walk you through integrating Composio with APIpie, enabling your AI applications to leverage over 250+ tools and services through a unified interface.

What is Composio?

Composio is a production-ready toolset for AI agents that provides a unified interface to over 250+ external tools and services. Key features include:

  • Extensive Tool Library: Access to tools like GitHub, Notion, Linear, Gmail, Slack, Hubspot, and more
  • OS Operations: File management, shell commands, code analysis, and other system-level operations
  • Search Capabilities: Integrations with Google, Perplexity, Tavily, Exa, and other search engines
  • Managed Authentication: Support for multiple auth protocols (OAuth, API Keys, Basic JWT)
  • Optimized Tool Calling: Up to 40% improved accuracy through specialized tool design
  • Framework Compatibility: Works with LLM frameworks like LangChain, CrewAI, AutoGen, and more

By connecting Composio with APIpie, you can enable your AI agents to interact with external services and tools while leveraging APIpie's powerful model selection and routing capabilities.


Integration Steps

1. Create an APIpie Account

2. Add Credit

3. Generate an API Key

  • API Key Management: APIpie API Keys
  • Create a new API key for use with Composio.

4. Install Composio

Install Composio and the OpenAI plugin:

pip install composio-core composio-openai

For JavaScript/TypeScript projects:

npm install composio-core
# or
yarn add composio-core
# or
pnpm add composio-core

5. Configure Composio with APIpie

Set up your environment variables:

# Get your API keys from respective platforms
export COMPOSIO_API_KEY=your-composio-api-key
export OPENAI_API_KEY=your-apipie-api-key
export OPENAI_BASE_URL=https://apipie.ai/v1

Key Features

  • Pre-built API Connectors: 250+ integrations ready to use without custom development
  • Authentication Management: Simplified auth handling for all connected tools
  • Tool Calling Optimization: Enhanced accuracy for AI tool usage
  • Multi-Framework Support: Works with various AI frameworks and LLM providers
  • Unified Interface: Consistent API for all external tools
  • Extensibility: Ability to create custom tool definitions

Example Workflows

Application TypeWhat Composio Helps You Build
Software IntegrationsAI agents that interact with GitHub, Notion, Slack, etc.
Email & CommunicationTools that read, write, and manage emails and messages
Data AnalysisApplications that fetch, analyze, and visualize external data
Research AssistantsAI that can search and compile information from various sources
Development WorkflowsCode review, repository management, and CI/CD automation

Using Composio with APIpie

Basic Python Integration

This example shows how to use Composio with APIpie to star a GitHub repository:

from openai import OpenAI
from composio_openai import ComposioToolSet, App, Action
import os

# Set up environment variables (can also be done in .env file)
os.environ["OPENAI_API_KEY"] = "your-apipie-api-key"
os.environ["OPENAI_BASE_URL"] = "https://apipie.ai/v1"
os.environ["COMPOSIO_API_KEY"] = "your-composio-api-key"

# Initialize OpenAI client with APIpie configuration
openai_client = OpenAI()

# Initialize the Composio Tool Set
composio_tool_set = ComposioToolSet()

# Connect your GitHub account (only needed once)
# Run 'composio add github' in terminal and follow the auth flow

# Get GitHub tools that are pre-configured
actions = composio_tool_set.get_actions(
actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]
)

# Define your task
my_task = "Star a repo composiodev/composio on GitHub"

# Create an assistant with the GitHub tools
assistant = openai_client.beta.assistants.create(
name="GitHub Assistant",
instructions="You are a helpful assistant that can interact with GitHub",
model="gpt-4o-mini", # Use any model supported by APIpie
tools=actions,
)

# Create a thread
thread = openai_client.beta.threads.create()

# Add user message to thread
message = openai_client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=my_task
)

# Execute the assistant with tool capabilities
run = openai_client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)

# Handle the tool calls and process the responses
response = composio_tool_set.wait_and_handle_assistant_tool_calls(
client=openai_client,
run=run,
thread=thread,
)

print(response)

Basic JavaScript Integration

import { OpenAIToolSet } from "composio-core";
import OpenAI from "openai";

// Configure APIpie as the OpenAI provider
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: "https://apipie.ai/v1"
});

// Initialize Composio toolset
const toolset = new OpenAIToolSet({
apiKey: process.env.COMPOSIO_API_KEY
});

// Connect your GitHub account (only needed once)
// Run 'composio add github' in terminal and follow the auth flow

// Get GitHub tools
const tools = await toolset.getTools({
actions: ["GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER"]
});

// Create GitHub assistant
const githubAssistant = await openai.beta.assistants.create({
name: "Github Assistant",
instructions: "You're a GitHub Assistant, you can perform operations on GitHub",
tools: tools,
model: "gpt-4o-mini" // Use any model supported by APIpie
});

// Create thread
const thread = await openai.beta.threads.create();

// Create run
const run = await openai.beta.threads.runs.create(thread.id, {
assistant_id: githubAssistant.id,
instructions: "Star the repository 'composiohq/composio'",
tools: tools,
model: "gpt-4o-mini",
stream: false
});

// Handle tool calls
const response = await toolset.waitAndHandleAssistantToolCalls(
openai,
run,
thread
);

console.log(response);

Multi-Tool Workflow Example

This example demonstrates using multiple tools together:

from openai import OpenAI
from composio_openai import ComposioToolSet, Action
import os

# Configure APIpie and Composio
os.environ["OPENAI_API_KEY"] = "your-apipie-api-key"
os.environ["OPENAI_BASE_URL"] = "https://apipie.ai/v1"
os.environ["COMPOSIO_API_KEY"] = "your-composio-api-key"

# Initialize clients
openai_client = OpenAI()
composio_tool_set = ComposioToolSet()

# Get multiple tool categories
actions = composio_tool_set.get_actions(
actions=[
# GitHub actions
Action.GITHUB_LIST_REPOSITORIES_FOR_THE_AUTHENTICATED_USER,
Action.GITHUB_GET_A_REPOSITORY,
# Notion actions
Action.NOTION_RETRIEVE_A_PAGE,
Action.NOTION_CREATE_A_PAGE,
# Google search action
Action.GOOGLE_SEARCH
]
)

# Create research assistant that can use all these tools
assistant = openai_client.beta.assistants.create(
name="Research Assistant",
instructions="""
You are a research assistant that can:
1. Search for information on Google
2. Check GitHub repositories for code examples
3. Create and retrieve Notion pages to store findings

Help users find information and organize it effectively.
""",
model="gpt-4o", # Use any model supported by APIpie
tools=actions,
)

# Create a thread
thread = openai_client.beta.threads.create()

# Add a complex research task
message = openai_client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="Research the latest developments in AI agents, find some GitHub repositories with examples, and create a Notion page summarizing your findings."
)

# Execute the assistant
run = openai_client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)

# Process all tool calls
response = composio_tool_set.wait_and_handle_assistant_tool_calls(
client=openai_client,
run=run,
thread=thread,
)

print(response)

Troubleshooting & FAQ

  • How do I authenticate with external services?
    Run composio add <service-name> in your terminal to start the authentication flow for any service (e.g., composio add github).

  • Which models are supported?
    Any model available via APIpie's OpenAI-compatible endpoint can be used with Composio.

  • How do I handle environment variables securely?
    Store your API keys in environment variables or use environment management tools like python-dotenv. Never commit API keys to repositories.

  • Can I use Composio with other frameworks?
    Yes, Composio supports multiple frameworks including LangChain, CrewAI, AutoGen, and others.

  • How do I add custom tools?
    Composio supports custom tool definitions. See the Composio documentation for details.

For more information, see the Composio documentation or the GitHub repository.


Support

If you encounter any issues during the integration process, please reach out on APIpie Discord for assistance.