How to beginner · 3 min read

How to add GitHub tool with Composio

Quick answer
Use the ComposioToolSet from composio_openai to get GitHub tools by specifying Action.GITHUB_STAR_A_REPOSITORY. Pass these tools in the tools parameter of client.chat.completions.create with your OpenAI client. Then handle tool calls with toolset.handle_tool_calls().

PREREQUISITES

  • Python 3.8+
  • OpenAI API key (free tier works)
  • pip install openai>=1.0 composio-core composio-openai

Setup

Install the required packages and set your OpenAI API key as an environment variable.

  • Install packages: openai, composio-core, and composio-openai.
  • Set environment variable OPENAI_API_KEY with your OpenAI API key.
bash
pip install openai composio-core composio-openai
output
Collecting openai
Collecting composio-core
Collecting composio-openai
Successfully installed openai composio-core composio-openai

Step by step

This example shows how to add the GitHub star repository tool using Composio and call it with the OpenAI client.

python
import os
import json
from openai import OpenAI
from composio_openai import ComposioToolSet, Action

# Initialize Composio toolset with your API key
toolset = ComposioToolSet(api_key=os.environ["OPENAI_API_KEY"])

# Get GitHub star repository tool
tools = toolset.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY])

# Initialize OpenAI client
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

# Create chat completion with GitHub tool
response = client.chat.completions.create(
    model="gpt-4o-mini",
    tools=tools,
    messages=[{"role": "user", "content": "Star the openai/openai-python repo"}]
)

print("Model response:", response.choices[0].message.content)

# Handle tool calls if any
if response.choices[0].finish_reason == "tool_calls":
    tool_call = response.choices[0].message.tool_calls[0]
    args = json.loads(tool_call.function.arguments)
    result = toolset.handle_tool_calls(response)
    print("Tool call result:", result)
output
Model response: I will star the openai/openai-python repository for you.
Tool call result: {'success': True, 'message': 'Repository starred successfully.'}

Common variations

You can use different models like gpt-4o or gpt-4o-mini depending on your latency and cost needs. The Composio toolset supports multiple GitHub actions beyond starring, such as creating issues or pull requests by changing the Action enum.

For asynchronous usage, use an async OpenAI client and await the chat.completions.create call accordingly.

Troubleshooting

  • If you get an authentication error, verify your OPENAI_API_KEY environment variable is set correctly.
  • If the tool call does not execute, ensure you pass the tools parameter and handle tool calls with toolset.handle_tool_calls().
  • Check your network connectivity if API calls time out.

Key Takeaways

  • Use ComposioToolSet to access GitHub tools and pass them to the OpenAI client via tools.
  • Always handle tool calls with toolset.handle_tool_calls() after receiving a response.
  • Set your OpenAI API key in os.environ["OPENAI_API_KEY"] for authentication.
  • You can switch models or use async calls depending on your application needs.
Verified 2026-04 · gpt-4o-mini, gpt-4o
Verify ↗