Webhook map
runcancelled(run.cancelled)completed(run.completed)failed(run.failed)
HTTP handler setup
app/api/webhook/route.ts
import { processWebhook } from "corsair";
import { corsair } from "@/server/corsair";
export async function POST(request: Request) {
const headers = Object.fromEntries(request.headers);
// With multiTenancy, give each tenant its own URL (/api/webhook?tenantId=acme):
// the query says whose account, secret and hooks handle the delivery.
const query = Object.fromEntries(new URL(request.url).searchParams);
// The raw text, not request.json(): signatures are checked over the exact bytes sent.
const body = await request.text();
const result = await processWebhook(corsair, headers, body, query);
if (!result.plugin) {
return Response.json({ success: false }, { status: 404 });
}
// A refusal (bad signature) carries no status and answers 400; a handler
// that threw comes back with 500, so the sender retries it.
const status =
result.response?.success === false ? (result.response.statusCode ?? 400) : 200;
return Response.json(result.response ?? { success: true }, {
status,
headers: result.responseHeaders,
});
}
Events
Run
Cancelled
run.cancelled
A run reached CANCELLED
Payload
| Name | Type | Required | Description |
|---|---|---|---|
event | run.cancelled | Yes | — |
run_id | string | Yes | — |
status | string | Yes | — |
data | object | No | — |
data full type
data full type
{
run_id?: string,
status?: string,
goal?: string,
created_at?: string,
started_at?: string | null,
finished_at?: string | null,
num_of_steps?: number | null,
result?: Record<string, any> | null,
error?: {
code?: string | null,
message?: string,
category?: string
} | null,
streaming_url?: string | null,
steps?: {
id: string,
timestamp: string,
status: string,
action?: string | null,
screenshot?: string | null,
html?: string | null,
duration?: string | null
}[]
}
Response data full type
Response data full type
{
event: run.cancelled,
run_id: string,
status: string,
data?: {
run_id?: string,
status?: string,
goal?: string,
created_at?: string,
started_at?: string | null,
finished_at?: string | null,
num_of_steps?: number | null,
result?: Record<string, any> | null,
error?: {
code?: string | null,
message?: string,
category?: string
} | null,
streaming_url?: string | null,
steps?: {
id: string,
timestamp: string,
status: string,
action?: string | null,
screenshot?: string | null,
html?: string | null,
duration?: string | null
}[]
}
}
webhookHooks example
tinyfish({
webhookHooks: {
run: {
cancelled: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Completed
run.completed
A run reached COMPLETED with its results attached
Payload
| Name | Type | Required | Description |
|---|---|---|---|
event | run.completed | Yes | — |
run_id | string | Yes | — |
status | string | Yes | — |
data | object | No | — |
data full type
data full type
{
run_id?: string,
status?: string,
goal?: string,
created_at?: string,
started_at?: string | null,
finished_at?: string | null,
num_of_steps?: number | null,
result?: Record<string, any> | null,
error?: {
code?: string | null,
message?: string,
category?: string
} | null,
streaming_url?: string | null,
steps?: {
id: string,
timestamp: string,
status: string,
action?: string | null,
screenshot?: string | null,
html?: string | null,
duration?: string | null
}[]
}
Response data full type
Response data full type
{
event: run.completed,
run_id: string,
status: string,
data?: {
run_id?: string,
status?: string,
goal?: string,
created_at?: string,
started_at?: string | null,
finished_at?: string | null,
num_of_steps?: number | null,
result?: Record<string, any> | null,
error?: {
code?: string | null,
message?: string,
category?: string
} | null,
streaming_url?: string | null,
steps?: {
id: string,
timestamp: string,
status: string,
action?: string | null,
screenshot?: string | null,
html?: string | null,
duration?: string | null
}[]
}
}
webhookHooks example
tinyfish({
webhookHooks: {
run: {
completed: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Failed
run.failed
A run reached FAILED with its error attached
Payload
| Name | Type | Required | Description |
|---|---|---|---|
event | run.failed | Yes | — |
run_id | string | Yes | — |
status | string | Yes | — |
data | object | No | — |
data full type
data full type
{
run_id?: string,
status?: string,
goal?: string,
created_at?: string,
started_at?: string | null,
finished_at?: string | null,
num_of_steps?: number | null,
result?: Record<string, any> | null,
error?: {
code?: string | null,
message?: string,
category?: string
} | null,
streaming_url?: string | null,
steps?: {
id: string,
timestamp: string,
status: string,
action?: string | null,
screenshot?: string | null,
html?: string | null,
duration?: string | null
}[]
}
Response data full type
Response data full type
{
event: run.failed,
run_id: string,
status: string,
data?: {
run_id?: string,
status?: string,
goal?: string,
created_at?: string,
started_at?: string | null,
finished_at?: string | null,
num_of_steps?: number | null,
result?: Record<string, any> | null,
error?: {
code?: string | null,
message?: string,
category?: string
} | null,
streaming_url?: string | null,
steps?: {
id: string,
timestamp: string,
status: string,
action?: string | null,
screenshot?: string | null,
html?: string | null,
duration?: string | null
}[]
}
}
webhookHooks example
tinyfish({
webhookHooks: {
run: {
failed: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})