Retrying HTTP Requests
When working with external APIs, network failures and temporary service outages are inevitable. The retry
option in lam.httpRequest
and lam.httpRequests
allows you to automatically retry failed requests.
The retry functionality is optional; just add a retry
object with maxAttempts
to your HTTP request.
Important: Retries are not enabled by default. You must explicitly specify retry behaviour when creating your workflow steps.
retry
Properties
maxAttempts
int
required
Total number of attempts (1 = no retry)
strategy
string
exponential
"exponential" or "fixed"
initialDelay
string/number
1s
First retry delay
maxDelay
string/number
30s
Maximum delay cap
multiplier
double
2.0
Exponential backoff multiplier
retryableStatusCodes
array[int]
[429,500,502,503,504]
HTTP status codes to retry
retryableExceptions
array[string]
["timeout","connection"]
Exception types to retry
Example: Suppose we're processing orders and need to reliably send them to external fulfillment services that occasionally experience temporary outages.
Send Order to Primary Warehouse (With Retry)
(data) => {
const { input } = data;
return {
"lam.httpRequest": {
method: "POST",
url: "{{config.primaryWarehouseUrl}}/api/orders",
headers: {
Authorization: "Bearer {{config.warehouseApiKey}}",
"Content-Type": "application/json",
},
body: {
orderId: input.orderId,
items: input.items,
priority: "high",
shippingAddress: input.shippingAddress,
},
// added here
retry: {
maxAttempts: 3,
},
},
};
};
Update Multiple Services (Batch Retry)
(data) => {
const { input } = data;
const fulfillmentResponse = data.step_2.response || data.step_1.response;
return {
"lam.httpRequests": [
{
method: "PUT",
url: `{{config.orderServiceUrl}}/orders/${input.orderId}/status`,
headers: {
Authorization: "Bearer {{config.orderServiceKey}}",
},
body: {
status: "processing",
trackingNumber: fulfillmentResponse.trackingNumber,
warehouse: fulfillmentResponse.warehouseId,
},
// added here
retry: {
maxAttempts: 2,
},
},
{
method: "POST",
url: "{{config.notificationServiceUrl}}/send-confirmation",
headers: {
Authorization: "Bearer {{config.notificationKey}}",
},
body: {
customerId: input.customerId,
orderId: input.orderId,
trackingNumber: fulfillmentResponse.trackingNumber,
type: "order_confirmed",
},
// added here
retry: {
maxAttempts: 4,
},
},
],
};
};
Last updated
Was this helpful?