π Introduction
-
iframe
is a standard protocol for embedding one website into another. - Iframes are particularly useful for enabling third-party agents with existing web applications to seamlessly onboard onto the MuleRun platform.
- MuleRun supports Iframe Agents as one of its primary agent integration methods, allowing external developers to host and manage their agent logic independently while being securely embedded within MuleRun.
ποΈ System Architecture

Component Summary
Component | Description |
---|---|
Agent Configuration Params | The param details when you create an Iframe agent from Creator Studio iframe agent template |
Iframe URL Protocol | The URL(s) that MuleRun opens when a user starts or resumes a session. Parameters are passed via query string for authentication and context. Separate URLs can be configured for starting and sharing sessions. |
Metering API | A MuleRun platform API that allows agent creators to report usage costs for a given session. Enables fine-grained billing based on resource consumption. |
Metering Get Reports API | A MuleRun platform API that allows agent creators to get the usage costs for a given session and its current session status. |
π Agent Configuration Params
Configuration Param | Usage | Default |
---|---|---|
Start Session Url | The Iframe url that starts a new session on creatorβs website | |
Share Session Url | The Iframe url that starts a new shared session(playback) on creatorβs website | |
Agent Key | The key used for generating signature AND calling metering api, this key should not be expose to any 3rd party | |
Max Age | The maximum age of the session, in minutes | 2880 |
Start Session Refresh Interval | The time interval between every two re-generations of start session full url(in minutes). when set to 0, it means the start session url will be created only once. | 0 |
π Iframe URL Protocol
Behavior Overview
- When a new session starts, MuleRun redirects the user to the Start Session URL, including all required parameters.
- On page refresh or re-entry into the session, the Start Session URL is loaded again with updated parameters.
- When a session ends (either terminated or time out), a Share Session URL may be triggered. The user may choose to view or share the session playback.
- When a visitor accesses the shared playback of a session, the Share Session URL is opened.
URL Schema Design
Note: All parameters are URL-encoded during transmission. During signature verification, they must be URL-decoded, parsed into a dictionary, sorted, and serialized as JSON before HMAC calculation.
Routing Example
Your agentβs endpoint:https://third-party-url.com/session/
Parameter Definitions
Parameter | Type | Example |
---|---|---|
userId | string (64 chars) | 3e5215afce4ef92284c336110cc6dd3d0107971687396cbb3dbbbc625bc3807d |
sessionId | string (36 chars, UUID) | 7469a916-d0c6-4161-bd33-1ebac5c834c4 |
agentId | string (36 chars, UUID) | 924751e0-196e-4b22-bdbd-f0a9ac6a4e39 |
time (UTC) | string (integer timestamp) | 1755667994 |
origin | string | mulerun.com |
nonce | string (36 chars, UUID) | bd3ff1f9-d5f3-4019-848a-7c74bba0b73a |
signature | string (64 chars, SHA-256 HMAC hex) | 2ae8a94f29beda81f59beca248824fcd91484c5f5744432a47ce2cea0a5c9a6f |
Example URL
Signature Generation (Python Example)
β
Important: Use json.dumps(..., sort_keys=True)
to ensure consistent serialization order.
Signature Verification (Python Example)
π The agent_key
is your Agent specific key that you can copy from your agent info in Creator Studio. It should be not be exposed to any 3rd party.
π Security Considerations
To ensure secure and trusted communication, the following mechanisms are implemented:Mechanism | Purpose |
---|---|
User ID Hashing | Raw user identifiers are hashed (e.g., SHA-256) to protect user privacy. |
HMAC Signature | Prevents tampering of query parameters. Ensures authenticity of the request. |
Timestamp Validation | Requests must be within a valid time window (e.g., Β±5 minutes) to prevent replay attacks. |
Origin Domain Whitelisting | Only specified domains are allowed to receive iframe requests. Prevents unauthorized embedding. |
Nonce Usage | Unique per-request identifier to prevent replay attacks and ensure freshness. |
β Recommended Validation Logic:
π Metering Report API
Used by agents to report usage and enable accurate billing.Endpoint
Headers
Header | Type | Required | Description |
---|---|---|---|
Authorization | string | Yes | Bearer token: Authorization: Bearer <your_agent_key_here> |
Content-Type | string | Yes | Must be application/json |
Request Body
Field Descriptions
Field | Type | Required | Description |
---|---|---|---|
agentId | string (UUID) | Yes | Unique ID assigned by MuleRun to identify the agent. |
sessionId | string (UUID) | Yes | Identifier for the current user session. Multiple reports with the same sessionId belong to the same session. |
cost | integer | Yes | Usage cost in units of 0.0001 credits. For example, 1050 = 0.105 credits. Must be positive. |
timestamp | string (ISO 8601 UTC) | Yes | UTC timestamp indicating when this usage was recorded. |
isFinal | boolean | No | If true , marks this as the final report for the session(AND session will be terminated). Defaults to false . |
meteringId | string (UUID v4 recommended) | Yes | A globally unique idempotency key. Prevents duplicate processing of the same report. |
β Idempotency Mechanism
-
New
meteringId
: The request is processed and stored. A success response is returned. -
Duplicate
meteringId
: The system returns the cached response without reprocessing. - This ensures safe retries without double billing.
π Additional Billing & Session Rules
1. Timestamp Ordering
-
All metering reports must have monotonically increasing
timestamp
values. - Out-of-order reports may be rejected or handled with warnings during auditing.
2. Final State Idempotency
-
Once a report with
"isFinal": true
is accepted for asessionId
, the session is marked as completed. -
Any further reports for the same
sessionId
will be ignored (cached response returned).
3. Session Termination Handling
- No Reports Received: If no metering reports are sent, MuleRun will charge based on internal resource tracking.
- Grace Period: If no final report is received before session end, late reports are accepted within 1 minute after termination.
- Abnormal Termination: In cases of crash or forced termination, the grace period does not apply β charges are settled immediately.
4. Negative Credit Balance
- If a userβs credit balance becomes negative, the session is immediately terminated.
- All subsequent metering reports for that session will be ignored.
β Success Response
Field | Type | Description |
---|---|---|
status | string | "success" indicates the report was accepted. |
meteringId | string | The idempotency key stored by MuleRun for this record. |
β Error Responses
400 Bad Request
401 Unauthorized
429 Too Many Requests
500 Internal Server Error
π‘ Example cURL Request
π οΈ Best Practice: Generate a new UUIDv4 for each meteringId
to ensure idempotency.
π Metering Get Reports API
API Endpoint
Headers
Name | Type | Required | Description |
---|---|---|---|
Authorization | string | Yes | Bearer token for authentication. Example: Authorization: Bearer <your_agent_key_here> |
Path Parameters
Parameter Name | Type | Required | Description |
---|---|---|---|
sessionId | string | Yes | Unique identifier of the session, passed via URL path |
Response Format
β Success Response
Field Descriptions
Top-Level Fields
Field | Type | Description |
---|---|---|
status | string | Fixed value "success" , indicates the query was successful |
data | object | Contains detailed session information |
data
Object Fields
Field | Type | Description |
---|---|---|
sessionId | string | Unique identifier of the session |
sessionStatus | string | Current status of the session. Possible values: running (in progress), completed (ended normally), error (ended with error) |
reportCount | number | Number of successfully processed metering reports |
isFinalReported | boolean | Whether the final report (isFinal=true ) has been received |
meteringRecords | array | List of successfully processed metering records |
Elements in meteringRecords
Array
Field | Type | Description |
---|---|---|
meteringId | string | Unique identifier from the metering API request |
isFinal | boolean | Indicates whether this is the final record |
Session Status Descriptions
Status Value | Description |
---|---|
running | The session is active and can accept new metering requests |
completed | The session has ended normally (either isFinal=true was reported or the session terminated properly) |
error | The session ended abnormally (e.g., platform failure or other errors) |