npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@composio/openai

v0.3.1

Published

The OpenAI provider for Composio SDK, providing seamless integration with OpenAI's models and function calling capabilities.

Readme

@composio/openai

The OpenAI provider for Composio SDK, providing seamless integration with OpenAI's models and function calling capabilities.

Features

  • OpenAI Integration: Seamless integration with OpenAI's models
  • Streaming Support: First-class support for streaming responses
  • Function Calling: Support for OpenAI's function calling feature
  • Tool Execution: Execute tools with proper parameter handling
  • Type Safety: Full TypeScript support with proper type definitions
  • Model Support: Support for all OpenAI models (GPT-4, GPT-3.5-turbo, etc.)
  • Responses API Support: First-class support for OpenAI's Responses API

Installation

npm install @composio/openai
# or
yarn add @composio/openai
# or
pnpm add @composio/openai

Environment Variables

Required environment variables:

  • COMPOSIO_API_KEY: Your Composio API key
  • OPENAI_API_KEY: Your OpenAI API key

Optional environment variables:

  • OPENAI_API_BASE: Custom API base URL (for Azure OpenAI)
  • OPENAI_ORGANIZATION: OpenAI organization ID

Quick Start

import { Composio } from '@composio/core';
import { OpenAIProvider, OpenAIResponsesProvider } from '@composio/openai';

// Initialize Composio with OpenAI provider
const composio = new Composio({
  apiKey: 'your-composio-api-key',
  provider: new OpenAIProvider(), // For Chat Completions API
  // OR
  provider: new OpenAIResponsesProvider(), // For Responses API
});

// Get available tools
const tools = await composio.tools.get('user123', {
  toolkits: ['gmail', 'googlecalendar'],
  limit: 10,
});

// Get a specific tool
const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');

Examples

Check out our complete example implementations:

Basic Chat Completion with Streaming

import { Composio } from '@composio/core';
import { OpenAIProvider } from '@composio/openai';
import OpenAI from 'openai';

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

// Example API route
export async function POST(req: Request) {
  const { messages } = await req.json();
  const tools = await composio.tools.get('user123', {
    toolkits: ['gmail'],
  });

  const stream = await openai.chat.completions.create({
    model: 'gpt-4',
    messages,
    tools,
    stream: true,
  });

  return new Response(stream, {
    headers: {
      'content-type': 'text/event-stream',
    },
  });
}

Using the Responses API

import { Composio } from '@composio/core';
import { OpenAIResponsesProvider } from '@composio/openai';
import OpenAI from 'openai';

const openai = new OpenAI();
const composio = new Composio({
  provider: new OpenAIResponsesProvider(),
});

// Get tools from Composio
const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');

// Generate initial response from OpenAI
const initialResponse = await openai.responses.create({
  model: 'gpt-4.1',
  input: 'Tell me about the user `pg` in hackernews',
  tools,
});

// Handle tool calls from response
const modelInputs = await composio.provider.handleResponse(
  'default',
  initialResponse,
  {},
  {
    beforeExecute: async (toolSlug, toolkitSlug, params) => {
      console.log(`🔄 Executing tool ${toolSlug} from toolkit ${toolkitSlug}...`);
      return params;
    },
    afterExecute: async (toolSlug, toolkitSlug, result) => {
      console.log(`✅ Tool ${toolSlug} executed`);
      return result;
    },
  }
);

// Submit tool outputs back to OpenAI
const finalResponse = await openai.responses.create({
  model: 'gpt-4.1',
  input: [...initialResponse.output, ...modelInputs],
  tools,
});

// Process the final response
const finalContent = finalResponse.output[0];
if (finalContent.type === 'message' && finalContent.content[0].type === 'output_text') {
  console.log(finalContent.content[0].text);
}

Tool Execution with Streaming

import { Composio } from '@composio/core';
import { OpenAIProvider } from '@composio/openai';
import OpenAI from 'openai';

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

// Example API route that handles tool execution
export async function POST(req: Request) {
  const { messages } = await req.json();
  const tools = await composio.tools.get('user123', {
    toolkits: ['gmail', 'googlecalendar'],
  });

  const stream = await openai.chat.completions.create({
    model: 'gpt-4',
    messages,
    tools,
    tool_choice: 'auto',
    stream: true,
  });

  const chunks = [];
  for await (const chunk of stream) {
    if (chunk.choices[0]?.delta?.tool_calls) {
      const toolCall = chunk.choices[0].delta.tool_calls[0];
      const result = await composio.provider.executeToolCall(toolCall);
      // Handle tool execution result
      chunks.push(result);
    } else {
      chunks.push(chunk.choices[0]?.delta?.content || '');
    }
  }

  return new Response(chunks.join(''), {
    headers: {
      'content-type': 'text/plain',
    },
  });
}

Provider Configuration

The OpenAI providers can be configured with various options:

// For Chat Completions API
const provider = new OpenAIProvider();

// For Responses API
const responsesProvider = new OpenAIResponsesProvider({
  // Whether to enforce strict parameter validation
  strict: true, // Default: false
});

API Reference

OpenAIProvider Class

The OpenAIProvider class extends BaseComposioProvider and provides OpenAI-specific functionality for the Chat Completions API.

Methods

executeToolCall(tool: ToolCall): Promise<string>

Executes a tool call and returns the result.

const result = await provider.executeToolCall(toolCall);

OpenAIResponsesProvider Class

The OpenAIResponsesProvider class extends BaseNonAgenticProvider and provides OpenAI-specific functionality for the Responses API.

Methods

handleResponse(userId: string, response: OpenAI.Responses.Response, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<OpenAI.Responses.ResponseInputItem.FunctionCallOutput[]>

Handles tool calls from an OpenAI response and returns the tool outputs.

const outputs = await provider.handleResponse('user123', response);
handleToolCalls(userId: string, toolCalls: OpenAI.Responses.ResponseOutputItem[], options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<OpenAI.Responses.ResponseInputItem.FunctionCallOutput[]>

Handles specific tool calls from an OpenAI response.

const outputs = await provider.handleToolCalls('user123', toolCalls);
executeToolCall(userId: string, tool: OpenAI.Responses.ResponseFunctionToolCall, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>

Executes a single tool call and returns the result.

const result = await provider.executeToolCall('user123', toolCall);

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

ISC License

Support

For support, please visit our Documentation or join our Discord Community.