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.1.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.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for composio_openai-0.18.1.tar.gz
Algorithm Hash digest
SHA256 50147cba10d69ce1c0ceb146c45978b947c64de5878456f25d1054d9bdbf66b2
MD5 fccc8776c209e830c2ed604ebbf0f9c8
BLAKE2b-256 c20162c83445242cdd77d552d3393c1161c32e3701a8ac70401236207d0c7204

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for composio_openai-0.18.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8dd75b50532400a6f7fd317437beb8139ce20aa4c0f0430bddff85787c4cf4a9
MD5 a57ba21dab16a8e652867b3b640d4a86
BLAKE2b-256 7e51c106cbd8833e68895d6a2d0357c340da9eb94a88afbd064092d3d77d46f3

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