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

Uploaded Python 3

File details

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

File metadata

  • Download URL: composio_openai-0.19.0.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.19.0.tar.gz
Algorithm Hash digest
SHA256 28a6496dcd5a471db3e6dd03b33d7d916f436945dcf556285b86bc33911b6d3e
MD5 dc9ea0ef254fb5ca0f0ab9d385ada612
BLAKE2b-256 0304b32d42735336ca11c4053b4d8ee392f5388813549dc13191943a2b4c2d41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for composio_openai-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3eb85ad57c0d26603cb4bceb71403769e9e8b7495eab83b7d47e2d8d897ae7a7
MD5 2530419111628b479eb5d6cc2f8e358d
BLAKE2b-256 c3dc347b54a64226cf5b8cde867de5450e2ec478d9665c302968c5b40c511f6e

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