Skip to main content

Use Composio to get an array of tools with your OpenAI Function Call.

Project description

composio-openai

Adapts Composio tools to OpenAI function calling, for both the Responses API and the Chat Completions API.

Installation

pip install composio composio-openai openai

Set COMPOSIO_API_KEY (create one at https://dashboard.composio.dev/settings) and OPENAI_API_KEY in your environment.

Quickstart

This package exports two providers: OpenAIResponsesProvider for the Responses API and OpenAIProvider for Chat Completions. Both are non-agentic: the model returns tool calls, you execute them with handle_tool_calls, and you feed the results back.

import json
from openai import OpenAI
from composio import Composio
from composio_openai import OpenAIResponsesProvider

composio = Composio(provider=OpenAIResponsesProvider())
client = OpenAI()

# Create a session for your user
session = composio.create(user_id="user_123")
tools = session.tools()

response = client.responses.create(
    model="gpt-5.2",
    tools=tools,
    input=[
        {
            "role": "user",
            "content": "Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'"
        }
    ]
)

# Agentic loop: keep executing tool calls until the model responds with text
while True:
    tool_calls = [o for o in response.output if o.type == "function_call"]
    if not tool_calls:
        break
    results = composio.provider.handle_tool_calls(response=response, user_id="user_123")
    response = client.responses.create(
        model="gpt-5.2",
        tools=tools,
        previous_response_id=response.id,
        input=[
            {"type": "function_call_output", "call_id": tool_calls[i].call_id, "output": json.dumps(result)}
            for i, result in enumerate(results)
        ]
    )

# Print final response
for item in response.output:
    if item.type == "message":
        print(item.content[0].text)

Chat Completions

OpenAIProvider targets client.chat.completions.create and is the Composio SDK default, so Composio() with no provider uses it. The loop is the same shape: call handle_tool_calls on each response, append the results as tool messages, and call the API again. See the docs page for the full example.

Links

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

composio_openai-0.18.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

composio_openai-0.18.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file composio_openai-0.18.0.tar.gz.

File metadata

  • Download URL: composio_openai-0.18.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for composio_openai-0.18.0.tar.gz
Algorithm Hash digest
SHA256 6c2c74fe1e3c244ba2408fed6dd43a3ca09cc0589a2830583c098f9ce9993c33
MD5 b56267de4f52d5f3f3714fcd107c5899
BLAKE2b-256 ae9400b044f3b9d0c305f59d46593c16b3accdc2b4a625c9a38cf9a1638ba7de

See more details on using hashes here.

File details

Details for the file composio_openai-0.18.0-py3-none-any.whl.

File metadata

File hashes

Hashes for composio_openai-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2d3e24f093c822d6d3fa357859edad222e6f4241cc4d6fcf95a12db79955578
MD5 d0409dbbe360caf992a9299a87f61e5c
BLAKE2b-256 1b29e4de48fa49ac5c04b48fe2ae43ed4723f038ccbc4fa2b897afad7b24ff19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page