AnthropicallyHuggingFaces's picture
Add Composio client
5b59a9b verified
Raw History Blame Contribute Delete
1.08 kB
"""Composio client - external app tool registry + execution."""
import os
import requests
BASE = os.getenv("COMPOSIO_API_BASE", "https://backend.composio.dev")
KEY = os.getenv("COMPOSIO_API_KEY")
def _h():
if not KEY:
raise RuntimeError("COMPOSIO_API_KEY not set")
return {"Authorization": f"Bearer {KEY}", "x-api-key": KEY, "Content-Type": "application/json"}
def list_tools(**params):
return requests.get(f"{BASE}/api/v1/tools", headers=_h(), params=params, timeout=60).json()
def get_tool(tool_name: str):
return requests.get(f"{BASE}/api/v1/tools/{tool_name}", headers=_h(), timeout=60).json()
def execute_action(app, action, params, connected_account_id=None):
body = {"app": app, "action": action, "params": params}
if connected_account_id:
body["connectedAccountId"] = connected_account_id
return requests.post(f"{BASE}/api/v1/actions/execute", headers=_h(), json=body, timeout=120).json()
def get_connected_accounts():
return requests.get(f"{BASE}/api/v1/connected_accounts", headers=_h(), timeout=60).json()