Webhook 支持从 LangSmith 应用程序到外部服务的事件驱动通信。例如,您可能希望在对 LangSmith 的 API 调用完成运行后向单独的服务发出更新。 许多 LangSmith 端点接受 webhook 参数。如果端点可以接受 POST 请求指定此参数,LangSmith 将在运行完成时发送请求。 在使用 LangSmith 时,您可能希望使用 webhook 在 API 调用完成后接收更新。Webhook 对于在运行完成处理后触发服务中的操作很有用。要实现这一点,您需要公开一个可以接受 POST 请求的端点,并将此端点作为 API 请求中的 webhook 参数传递。 目前,SDK 不提供定义 webhook 端点的内置支持,但您可以使用 API 请求手动指定它们。

支持的端点

以下 API 端点接受 webhook 参数:
操作HTTP 方法端点
创建运行POST/thread/{thread_id}/runs
创建线程 CronPOST/thread/{thread_id}/runs/crons
流式传输运行POST/thread/{thread_id}/runs/stream
等待运行POST/thread/{thread_id}/runs/wait
创建 CronPOST/runs/crons
流式传输无状态运行POST/runs/stream
等待无状态运行POST/runs/wait
在本指南中,我们将展示如何在流式传输运行后触发 webhook。

设置您的助手和线程

在进行 API 调用之前,设置您的助手和线程。
  • Python
  • JavaScript
  • CURL
from langgraph_sdk import get_client

client = get_client(url=<DEPLOYMENT_URL>)
assistant_id = "agent"
thread = await client.threads.create()
print(thread)
Example response:
{
    "thread_id": "9dde5490-2b67-47c8-aa14-4bfec88af217",
    "created_at": "2024-08-30T23:07:38.242730+00:00",
    "updated_at": "2024-08-30T23:07:38.242730+00:00",
    "metadata": {},
    "status": "idle",
    "config": {},
    "values": null
}

在图运行中使用 webhook

要使用 webhook,请在 API 请求中指定 webhook 参数。当运行完成时,LangSmith 会向指定的 webhook URL 发送 POST 请求。 例如,如果您的服务器在 https://my-server.app/my-webhook-endpoint 侦听 webhook 事件,请在请求中包含此内容:
  • Python
  • JavaScript
  • CURL
input = { "messages": [{ "role": "user", "content": "Hello!" }] }

async for chunk in client.runs.stream(
    thread_id=thread["thread_id"],
    assistant_id=assistant_id,
    input=input,
    stream_mode="events",
    webhook="https://my-server.app/my-webhook-endpoint"
):
    pass

Webhook payload

LangSmith sends webhook notifications in the format of a Run. See the API Reference for details. The request payload includes run input, configuration, and other metadata in the kwargs field.

Secure webhooks

To ensure only authorized requests hit your webhook endpoint, consider adding a security token as a query parameter:
https://my-server.app/my-webhook-endpoint?token=YOUR_SECRET_TOKEN
Your server should extract and validate this token before processing requests.

Disable webhooks

As of langgraph-api>=0.2.78, developers can disable webhooks in the langgraph.json file:
{
  "http": {
    "disable_webhooks": true
  }
}
This feature is primarily intended for self-hosted deployments, where platform administrators or developers may prefer to disable webhooks to simplify their security posture—especially if they are not configuring firewall rules or other network controls. Disabling webhooks helps prevent untrusted payloads from being sent to internal endpoints. For full configuration details, refer to the configuration file reference.

Test webhooks

You can test your webhook using online services like:
  • Beeceptor – Quickly create a test endpoint and inspect incoming webhook payloads.
  • Webhook.site – View, debug, and log incoming webhook requests in real time.
These tools help you verify that LangSmith is correctly triggering and sending webhooks to your service.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.