Triggers
Execute workflows via API, webhooks, or schedules.
Trigger Types
API
Execute on-demand from your application code.
Webhook
Trigger from external services (Slack, GitHub, etc.).
Schedule
Run automatically on a cron schedule.
API Execution
Execute workflows directly from your application:
// Execute a workflow via API
const response = await fetch('https://api.llmhub.dev/v1/workflow/execute', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
workflow_id: 'wf_abc123',
input: {
message: 'Hello, how can I help you?',
user_id: 'user_xyz'
},
stream: false // Set true for SSE streaming
})
});
const result = await response.json();
console.log(result);
// {
// "execution_id": "exec_def456",
// "status": "completed",
// "output": { "response": "I'm here to help! What do you need?" },
// "usage": { "prompt_tokens": 150, "completion_tokens": 25 },
// "duration_ms": 1234
// }Streaming Execution
Stream workflow progress and outputs in real-time using Server-Sent Events:
// Execute with SSE streaming
const response = await fetch('https://api.llmhub.dev/v1/workflow/execute', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
workflow_id: 'wf_abc123',
input: { message: 'Tell me a story' },
stream: true
})
});
const reader = response.body?.getReader();
const decoder = new TextDecoder();
while (reader) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('event: ')) {
const eventType = line.slice(7);
console.log('Event:', eventType);
}
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
console.log('Data:', data);
}
}
}
// Events:
// event: node_start
// data: {"nodeId":"llm_1","timestamp":"..."}
//
// event: node_output
// data: {"nodeId":"llm_1","chunk":"Once upon a time..."}
//
// event: node_complete
// data: {"nodeId":"llm_1","duration":1234}
//
// event: workflow_complete
// data: {"output":{...},"usage":{...}}| Event | Description |
|---|---|
node_start | Node begins executing |
node_output | Partial output from a streaming node |
node_complete | Node finished with final output |
node_error | Node encountered an error |
workflow_complete | Workflow finished successfully |
workflow_error | Workflow failed |
Webhook Triggers
Create webhook endpoints that trigger your workflow when called:
// Create a webhook trigger for a workflow
const response = await fetch('https://api.llmhub.dev/v1/webhooks', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
workflow_id: 'wf_abc123',
name: 'Customer Support Webhook',
path: 'support-bot', // Becomes /v1/hooks/support-bot
method: 'POST',
secret: 'your-hmac-secret' // For signature verification
})
});
const webhook = await response.json();
// {
// "id": "wh_xyz789",
// "url": "https://api.llmhub.dev/v1/hooks/support-bot",
// "secret": "your-hmac-secret"
// }Triggering the Webhook
External services can call your webhook URL:
// Trigger the workflow via webhook (from external service)
curl -X POST https://api.llmhub.dev/v1/hooks/support-bot \
-H "Content-Type: application/json" \
-H "X-Webhook-Signature: sha256=abc123..." \
-d '{"customer_id": "c_123", "message": "I need help with my order"}'
# Response:
# {
# "execution_id": "exec_def456",
# "status": "completed",
# "output": { "response": "I'd be happy to help..." }
# }Signature Verification
Include the X-Webhook-Signature header with an HMAC-SHA256 signature of the request body using your secret. We verify this before executing the workflow.
Input Mapping
The webhook body is passed as the workflow input. Use the Start node to define the expected schema.
Scheduled Triggers
Run workflows automatically on a schedule using cron expressions:
// Create a scheduled trigger
const response = await fetch('https://api.llmhub.dev/v1/schedules', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
workflow_id: 'wf_abc123',
name: 'Daily Report Generator',
cron: '0 9 * * *', // Every day at 9 AM
timezone: 'America/New_York',
input: {
report_type: 'daily_summary'
},
enabled: true
})
});
const schedule = await response.json();
// {
// "id": "sch_abc123",
// "next_run": "2024-01-16T09:00:00-05:00",
// "cron": "0 9 * * *"
// }Cron Expression Examples
// Common cron expressions
"0 * * * *" // Every hour at minute 0
"*/15 * * * *" // Every 15 minutes
"0 9 * * *" // Daily at 9:00 AM
"0 9 * * 1-5" // Weekdays at 9:00 AM
"0 0 * * 0" // Weekly on Sunday at midnight
"0 0 1 * *" // Monthly on the 1st at midnight
"0 9,17 * * *" // Daily at 9 AM and 5 PMCron Format
ββββββββββββββ minute (0 - 59)
β ββββββββββββββ hour (0 - 23)
β β ββββββββββββββ day of month (1 - 31)
β β β ββββββββββββββ month (1 - 12)
β β β β ββββββββββββββ day of week (0 - 6, Sunday = 0)
β β β β β
* * * * *
Managing Triggers
List Triggers
Enable/Disable
Delete Trigger
View Execution History
Best Practices
Always Verify Webhook Signatures
Don't skip signature verification in productionβit prevents unauthorized workflow execution.
Use Streaming for Long Workflows
For workflows that take more than a few seconds, use streaming to avoid timeouts and show progress.
Set Appropriate Timeouts
Configure timeouts on your HTTP client. Workflow execution has a maximum of 5 minutes.
Handle Retries for Schedules
Scheduled workflows that fail are retried up to 3 times with exponential backoff. Design your workflow to be idempotent.

