Experimental

Webhooks

A webhook sends each tool call to an endpoint you host, before or after the tool runs. You respond to allow the tool call, block it, or modify it.

Webhooks are available only on the Enterprise plan.

Here are a few examples of what you can do with webhooks:

  • Screen for sensitive data: Scan tool calls for PII with your own detection service, and block the ones that contain it.
  • Enforce access policies: Check each tool call against your own permission or approval system.
  • Redact tool results: Strip secrets from a tool's result before your agent reads it.

Set up a webhook URL

You can configure the webhook URL from the dashboard, under Project Settings → General. In the Configuration section, find Tool execution webhook and click Configure. This is a project-level setting, so every session in the project that has a webhook uses the same URL. Only organization admins can set or change the URL. Users with the "Developer" or "Viewer" role can only view it.

When you save the URL, the dashboard displays a signing secret. Every request is signed with this secret, so you can verify that a request came from Composio before acting on it. If the secret is ever exposed, rotate it from the same page. The previous secret stops working immediately.

The dashboard shows the secret only once, either when you first save the URL or when you rotate the secret, so copy it and save it in your project's environment. If you change the URL later, the secret stays the same.

Add a webhook to a session

Once you've configured the URL, you can add webhooks to your sessions. Add a hook and set its handler type to webhook:

session = composio.create(
    user_id="user_123",
    hooks=[
        {
            "id": "check_gmail_calls",
            "type": "before_execute",
            "applies_to": {"toolkits": ["gmail"]},
            "handler": {
                "type": "webhook",
                "fallback_action": "block",
                "timeout_ms": 1000,
            },
        },
    ],
)

Set fallback_action to choose what happens to a tool call if there's no valid response from your endpoint, and timeout_ms to choose how long to wait for one. See Timeouts and Fallback.

Request and response payloads

For every tool call a webhook applies to, your endpoint receives a POST request. Read the request, decide what should happen to the tool call, and respond.

Request payload

This is the request for a tool call, sent before the tool runs:

{
  "id": "msg_3f2a9c1e-5b7d-4e8a-9c21-7d4e5f6a8b90",
  "type": "composio.session_hook.before_execute",
  "timestamp": "2026-11-20T12:00:00.000Z",
  "metadata": {
    "project_id": "pr_123",
    "session_id": "trs_123",
    "user_id": "user_123",
    "hook_id": "check_gmail_calls",
    "tool_call_id": "tc_V1StGXR8_Z5jdHi6"
  },
  "data": {
    "type": "tool_execute",
    "tool_call": {
      "toolkit_slug": "gmail",
      "tool_slug": "GMAIL_SEND_EMAIL",
      "toolkit_version": "20261101_00",
      "connected_account_id": "ca_123",
      "arguments": {
        "recipient_email": "jane@customer.com",
        "subject": "Pricing"
      }
    }
  }
}

The contents of data depend on the kind of call and on when the webhook runs:

before_executeafter_execute
Tool call ("type": "tool_execute")tool_calltool_call and tool_response
Proxy call ("type": "proxy_execute")http_requesthttp_request and http_response

For example, this is data for a tool call after it has run:

{
  "type": "tool_execute",
  "tool_call": {
    "toolkit_slug": "gmail",
    "tool_slug": "GMAIL_SEND_EMAIL",
    "toolkit_version": "20261101_00",
    "connected_account_id": "ca_123",
    "arguments": {
      "recipient_email": "jane@customer.com",
      "subject": "Pricing"
    }
  },
  "tool_response": {
    "data": { "id": "19a2b3c4d5e6f7a8" },
    "error": null
  }
}

And this is data for a proxy call after it has run:

{
  "type": "proxy_execute",
  "http_request": {
    "toolkit_slug": "github",
    "connected_account_id": "ca_456",
    "method": "GET",
    "endpoint": "/user/repos",
    "parameters": [{ "name": "per_page", "value": "10", "type": "query" }]
  },
  "http_response": {
    "status": 200,
    "headers": { "content-type": "application/json" },
    "data": [{ "name": "hello-world", "private": false }]
  }
}

Use metadata.tool_call_id to match the before_execute and after_execute requests for the same tool call. Both carry the same ID.

Response payload

Respond with HTTP 200 and a JSON body. There are three ways to respond:

ResponseWhat happens
{ "action": "continue" }The tool call goes ahead unchanged.
{ "action": "block", "message": "..." }The tool call is blocked.
{ "action": "continue", "override": { ... } }The tool call goes ahead with your changes.

When you block a tool call, your agent sees it fail, with your message as the error. Use the message to explain why you blocked the tool call. This works the same way from before_execute and after_execute. See Blocked tool calls for what's returned.

What goes in override also depends on the kind of call and on when the webhook runs:

before_executeafter_execute
Tool call{ "tool_call": { "arguments": { ... } } }{ "tool_response": { "data": { ... } } }
Proxy call{ "http_request": { ... } }{ "http_response": { ... } }

For a tool call, the arguments or data you return replace the originals entirely, so start from them and change only what you need. For a proxy call, include only the fields you want to change. Each field you include replaces the original in full.

For the full schema of the request and of your response, see the reference for before_execute and after_execute.

Example

Here's an example that receives a request, verifies it, and responds. The example uses FastAPI.

import os

from composio import Composio
from fastapi import FastAPI, Request

composio = Composio()
app = FastAPI()


@app.post("/composio/session-webhook")
async def session_webhook(request: Request):
    # parse() verifies the request signature against your secret and returns
    # the typed event. It raises an error if verification fails.
    # Pass the raw body: the signature is computed over its exact bytes.
    hook = composio.sessions.webhooks.parse(
        body=await request.body(),
        headers=request.headers,
        verify_secret=os.environ["COMPOSIO_SESSION_WEBHOOK_SECRET"],
    )

    # Decide if the tool call in `hook` should run.
    # To block it: return {"action": "block", "message": "..."}
    # To change it: return {"action": "continue", "override": {...}}
    return {"action": "continue"}

Timeouts

By default, you have 3 seconds to respond. You can change this by setting timeout_ms on the handler to any value between 100 and 5000 milliseconds.

{ "type": "webhook", "fallback_action": "block", "timeout_ms": 1000 }

Fallback

fallback_action is a required field. Set it to choose what happens to a tool call when there's no valid response from your endpoint:

  • block: The tool call is blocked. Use this when a tool call must never go through unchecked.
  • continue: The tool call goes ahead without your check. Use this when your agent should keep working even if your endpoint is down.

The fallback applies when:

  • The request times out, or your endpoint can't be reached.
  • You respond with a status other than 200.
  • Your response doesn't match the expected format.

Your endpoint receives each request once, with no retries. When the fallback applies, the webhook shows as unavailable in the tool call's hook_results:

{ "id": "check_gmail_calls", "status": "unavailable", "detail": "The webhook endpoint timed out" }

Limits

You can add one before_execute webhook and one after_execute webhook to a session.

Order of execution

A webhook can modify a tool call, so it always runs before custom prompt check and prompt injection detection hooks. That way, those hooks evaluate the tool call with your changes. This is the same for before_execute and after_execute.