webhook 参数。如果端点可以接受 POST 请求指定此参数,LangSmith 将在运行完成时发送请求。
在使用 LangSmith 时,您可能希望使用 webhook 在 API 调用完成后接收更新。Webhook 对于在运行完成处理后触发服务中的操作很有用。要实现这一点,您需要公开一个可以接受 POST 请求的端点,并将此端点作为 API 请求中的 webhook 参数传递。
目前,SDK 不提供定义 webhook 端点的内置支持,但您可以使用 API 请求手动指定它们。
支持的端点
以下 API 端点接受webhook 参数:
| 操作 | HTTP 方法 | 端点 |
|---|---|---|
| 创建运行 | POST | /thread/{thread_id}/runs |
| 创建线程 Cron | POST | /thread/{thread_id}/runs/crons |
| 流式传输运行 | POST | /thread/{thread_id}/runs/stream |
| 等待运行 | POST | /thread/{thread_id}/runs/wait |
| 创建 Cron | POST | /runs/crons |
| 流式传输无状态运行 | POST | /runs/stream |
| 等待无状态运行 | POST | /runs/wait |
设置您的助手和线程
在进行 API 调用之前,设置您的助手和线程。- Python
- JavaScript
- CURL
在图运行中使用 webhook
要使用 webhook,请在 API 请求中指定webhook 参数。当运行完成时,LangSmith 会向指定的 webhook URL 发送 POST 请求。
例如,如果您的服务器在 https://my-server.app/my-webhook-endpoint 侦听 webhook 事件,请在请求中包含此内容:
- Python
- JavaScript
- CURL
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 thekwargs field.
Secure webhooks
To ensure only authorized requests hit your webhook endpoint, consider adding a security token as a query parameter:Disable webhooks
As oflanggraph-api>=0.2.78, developers can disable webhooks in the langgraph.json file:
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.