HTTP Transitions – External API Integration in AgetnticOS
HTTP transitions connect your agentic processes to the outside world. They make REST API calls, process responses, handle authentication, implement retry logic, and route results based on HTTP status codes or response content.
HTTP transitions call external APIs and emit parsed response data to success or error places.
Basic HTTP Inscription Structure
{
"id": "t-call-api",
"kind": "http",
"mode": "SINGLE",
"presets": {
"input": {
"placeId": "api-requests",
"host": "myModel@localhost:8080",
"arcql": "FROM $ LIMIT 1",
"take": "FIRST",
"consume": true
}
},
"postsets": {
"success": { "placeId": "api-success", "host": "myModel@localhost:8080" },
"error": { "placeId": "api-error", "host": "myModel@localhost:8080" }
},
"action": {
"type": "http",
"method": "POST",
"url": "https://api.example.com/orders",
"headers": {
"Content-Type": "application/json"
},
"body": {
"orderId": "${input.data.orderId}",
"amount": "${input.data.amount}"
}
},
"emit": [
{ "to": "success", "from": "@response.json", "when": "success" },
{ "to": "error", "from": "@response.json", "when": "error" }
]
}
Key components:
kind: "http"– identifies this as an HTTP transitionaction.method– GET, POST, PUT, DELETE, PATCHaction.url– target endpoint (supports${...}interpolation)action.body– request body with template interpolationemit.from: "@response.json"– emits parsed JSON response body
Response Data Access
HTTP transitions provide two ways to access response data:
<pre class="wp-block-syntaxhighlighter-code">// Route by response content
"emit": [
{ "to": "created", "from": "@response.json", "when": "status == 'created'" },
{ "to": "updated", "from": "@response.json", "when": "status == 'updated'" }
]
// Route by HTTP status code
"emit": [
{ "to": "success", "from": "@response.meta", "when": "status >= 200 AND status < 300" },
{ "to": "error", "from": "@response.meta", "when": "status >= 400" }
]</pre>
Authentication Methods
HTTP transitions support multiple authentication schemes:
Basic Authentication
"action": {
"type": "http",
"method": "GET",
"url": "https://api.example.com/protected",
"auth": {
"type": "basic",
"username": "myuser",
"password": "mypassword"
}
}
Bearer Token
"action": {
"type": "http",
"method": "GET",
"url": "https://api.example.com/data",
"auth": {
"type": "bearer",
"token": "eyJhbGciOiJIUzI1NiIs..."
}
}
API Key
"action": {
"type": "http",
"method": "GET",
"url": "https://api.example.com/data",
"auth": {
"type": "api_key",
"key": "X-API-Key",
"value": "my-secret-key",
"in": "header" // or "query"
}
}
Retry Configuration
HTTP transitions support automatic retry with exponential backoff:
"action": {
"type": "http",
"method": "POST",
"url": "https://api.example.com/orders",
"retry": {
"maxAttempts": 3,
"initialDelayMs": 1000,
"multiplier": 2.0,
"retryOn": ["5xx", "429", "io_error"]
}
}
Retry conditions:
5xx– server errors (500, 502, 503, etc.)429– rate limitingio_error– network failures, timeouts
URL and Body Interpolation
Both URL and body support template interpolation from token data:
"action": {
"type": "http",
"method": "GET",
"url": "https://api.example.com/orders/${input.data.orderId}",
"headers": {
"X-Request-Id": "${input._meta.id}"
}
}
// POST with interpolated body
"action": {
"type": "http",
"method": "POST",
"url": "https://api.example.com/orders",
"body": {
"orderId": "${input.data.orderId}",
"customer": "${input.data.customerName}",
"items": "${input.data.lineItems}",
"requestedBy": "${input._meta.name}"
}
}
Complete Example: Order Processing API
{
"id": "t-process-order",
"kind": "http",
"mode": "SINGLE",
"presets": {
"input": {
"placeId": "pending-orders",
"host": "orders-model@localhost:8080",
"arcql": "FROM $ WHERE $.data.status==\"pending\" LIMIT 1",
"take": "FIRST",
"consume": true
}
},
"postsets": {
"confirmed": { "placeId": "confirmed-orders", "host": "orders-model@localhost:8080" },
"review": { "placeId": "pending-review", "host": "orders-model@localhost:8080" },
"failed": { "placeId": "failed-orders", "host": "orders-model@localhost:8080" }
},
"action": {
"type": "http",
"method": "POST",
"url": "https://api.orders.com/v1/process",
"headers": { "Content-Type": "application/json" },
"body": {
"orderId": "${input.data.orderId}",
"amount": "${input.data.amount}",
"customer": "${input.data.customerName}"
},
"auth": {
"type": "bearer",
"token": "${env.ORDERS_API_TOKEN}"
},
"retry": {
"maxAttempts": 3,
"initialDelayMs": 1000,
"retryOn": ["5xx", "429"]
},
"timeoutMs": 30000
},
"emit": [
{ "to": "confirmed", "from": "@response.json", "when": "status == 'confirmed'" },
{ "to": "review", "from": "@response.json", "when": "status == 'pending_review'" },
{ "to": "failed", "from": "@response.json", "when": "error" }
]
}
Summary
- kind: “http” – identifies the transition type
- emit.from: “@response.json” – parsed JSON response body
- emit.from: “@response.meta” – HTTP status and headers
- Authentication – basic, bearer, api_key
- Retry – automatic with exponential backoff
- Template interpolation – URL, headers, and body support
${...}
HTTP transitions bridge your Petri nets to external systems – use them for API integrations, webhooks, and service-to-service communication.