File size: 1,076 Bytes
5b59a9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""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()