Skip to main content

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

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for composio_openai-0.18.2.tar.gz
Algorithm Hash digest
SHA256 72a28fafe2744d87bb4878d2a3d8ce671a2f6a79bc0084a52c4427142b4b659f
MD5 3a2e0609f05e668a3e01120591ebb5d5
BLAKE2b-256 2eb5e1ff024868c0c79b5af6ee0dbbd2ecd43b5cef10184f359f4781d6024b4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for composio_openai-0.18.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1ee25bd49191d4370e3b5f04b5e4d0ab7defb00cfb2ea90d7b813c1528436345
MD5 03057ef48b2b30a0298a10b0e02b0526
BLAKE2b-256 7aa4f9cea121ad048cc585d3f053544b1015d0bdcc5bcda1d6a6d3721b05c2c0

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

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