---
updatedAt: 2025-08-07T13:38:46.000Z
agentTools:
  projectIndex: https://docs.metakeep.xyz/llms.txt
---

# Invoke Lambda

After the lambda is created from the `/v2/app/lambda/create` API call or imported using the `/v2/app/lambda/import` API, use this API to execute a lambda(smart contract) function.

Here are some sample requests:

```json Invoke as developer
{
  "lambda": "0x94f943354dB6710da3010bA4F9646402DEC1C73c",
  "function": {
    "name": "mint",
    "args": [
      "123"
    ]
  },
  "description": {
    "text": "mint an NFT"
  }
}
```
```json Invoke as end user
{
  "lambda": "0x94f943354dB6710da3010bA4F9646402DEC1C73c",
  "function": {
    "name": "mint",
    "args": [
      "123"
    ]
  },
  "as": {
    "email": "john@email.com"
  },
  "description": {
    "text": "mint an NFT",
    "image": "https://valid_image_url......"
  }
}
```
```json Invoke with a payment
{
  "lambda": "0x94f943354dB6710da3010bA4F9646402DEC1C73c",
  "function": {
    "name": "mint",
    "args": [
      "123"
    ]
  },
  "pay": "0.3",
  "as": {
    "email": "rickyrohan14@gmail.com"
  },
  "description": {
    "text": "mint an NFT"
  }
}
```

## Invoking without `as` user

If you don't provide an `as` user in the request body, lambda will be invoked from your developer account and a transaction will be raised and submitted to the Queue on the blockchain. MetaKeep, behind the scenes, employs several strategies to make sure transactions succeed, and at the lowest cost.

You can get the status of this blockchain transaction by querying for transaction status by copying the transactionId from this API response and querying it in [Transaction Status API](https://docs.metakeep.xyz/reference/v2apptransactionstatus).

> ❗️ Replaying this API
>
> Once you get a `status` response as `QUEUED`, replaying this API doesn't give you the latest status; Replaying the same API with the same [`Idempotency-Key`](/reference/idempotency-key) results in the same response, always with status-`QUEUED`. You must query the [Transaction Status](https://docs.metakeep.xyz/reference/v2apptransactionstatus) API for the latest status.

As you would learn from the [Transaction Status](https://docs.metakeep.xyz/reference/v2apptransactionstatus) API docs, if a transaction failed, MetaKeep would have exhausted all feasible smart AI-based strategies to recover from failure, that would have been attempted by humans, and the "FAILED" status, if shown, is final.

## Invoking with `as` user

If you provide an `as` user in the request body, you will get a `consentToken` back and you will have to use [Get Consent](https://docs.metakeep.xyz/reference/get-consent) flow to finish the lambda invocation. Here, the developer is agreeing to pick up the gas fee on execution so that the user doesn't have to know/understand the concept of gas. MetaKeep, behind the scenes, employs several strategies to make sure transactions succeed, and at the lowest cost.

```json Sample Response
{
  "status": "USER_CONSENT_NEEDED",
  "consentToken": "CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw=="
}
```

## Payment (aka Value Transfer)

You can send an optional payment(value) to a payable lambda function using the `pay` parameter. This is useful if you want to pay the lambda function for performing some operation. For example, if you want to pay the lambda function for minting an NFT, you can use the `pay` parameter to send the payment to the lambda function.

> 📘 Note that the payment is only supported when using `BUSINESS_WALLET`

## Gas Limit

This API currently has `gas limit` set to `2000000(2M)`. If you need a higher `gas limit`, please let us know.

## Gas Price

The API sets the right gas price for the transaction based on AI and statistical analysis of the current network conditions for `fast and reliable transaction` confirmation. If you want even faster confirmation, you can tune the transaction speed in the [app settings](https://docs.metakeep.xyz/docs/lambda-customization).

## Error Status

> 🚧 Api Error Status
>
> You can find error status returned by the api [here](https://docs.metakeep.xyz/reference/api-error-status#v2applambdainvoke).

© Copyright 2024, Passbird Research Inc.

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "production",
    "version": "3.4"
  },
  "servers": [
    {
      "url": "https://api.metakeep.xyz/"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/v2/app/lambda/invoke": {
      "post": {
        "summary": "Invoke Lambda",
        "description": "",
        "operationId": "v2applambdainvoke",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "description": "An idempotency key is a unique value generated by the client which the server uses to recognize subsequent retries of the same request. This allows developers to safely retry requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response. [Read more](/reference/idempotency-key)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "lambda",
                  "function",
                  "description"
                ],
                "properties": {
                  "lambda": {
                    "type": "string",
                    "description": "Hex encoded lambda address. This is obtained from a previous `/v2/app/lambda/create` or `/v2/app/lambda/import` API call"
                  },
                  "function": {
                    "type": "object",
                    "description": "Lambda Function to invoke with arguments in the format `{ name: \"function_name\", args: [] }`.",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "Function name.",
                        "default": "function_name"
                      },
                      "args": {
                        "type": "array",
                        "description": "Array of function arguments. This can be left empty if the function takes no arguments. Arguments should be sent in the format described [here](https://docs.metakeep.xyz/reference/lambda-101#solidity-types-to-lambda-types).",
                        "default": [
                          "123"
                        ],
                        "items": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "pay": {
                    "type": "string",
                    "description": "How much `native currency`(e.g. MATIC on Polygon) to pay(aka `value transfer`) to the payable lambda function. This should be a decimal string with up to 18 decimals. Only supported when using `BUSINESS_WALLET`"
                  },
                  "description": {
                    "type": "object",
                    "description": "The human understandable explanation for this transaction. Useful for presenting to the user as an extra information ex: `Swap wBTC to USDC`, and for auditing purposes. The description should include a text and an optional image.",
                    "required": [
                      "text"
                    ],
                    "properties": {
                      "text": {
                        "type": "string",
                        "description": "Human understandable text explaining the transaction."
                      },
                      "image": {
                        "type": "string",
                        "description": "An optional image URL to show along with the text."
                      }
                    }
                  },
                  "as": {
                    "type": "object",
                    "description": "Invoke lambda `as` this user. If this is not set, lambda will be invoked from your developer account.",
                    "properties": {
                      "email": {
                        "type": "string",
                        "description": "Email address of the user"
                      }
                    }
                  },
                  "using": {
                    "type": "string",
                    "description": "The lambda wallet type to use for the transaction. This can be either be empty or BUSINESS_WALLET.",
                    "enum": [
                      "BUSINESS_WALLET"
                    ]
                  }
                }
              },
              "examples": {
                "Payment as a User": {
                  "value": {
                    "lambda": "0xc5fd96683659C62b5db12F82dB330Af04d7efaEC",
                    "function": {
                      "name": "mint",
                      "args": [
                        "123"
                      ]
                    },
                    "pay": "0.00333",
                    "as": {
                      "email": "john@gmail.com"
                    },
                    "description": {
                      "text": "mint an NFT",
                      "image": "https://valid_image_url......"
                    },
                    "using": "BUSINESS_WALLET"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Invoke as a developer": {
                    "value": "{\n  \"status\": \"QUEUED\",\n  \"transactionId\": \"2d59c2f4-9766-451d-91f2-b7bcb96f51d0\",\n  \"transactionHash\": \"0xb1470e0c34729974bee524b9eced35d1d553bd26e184679aa7a9e77c7571884f\",\n  \"transactionChainScanUrl\": \"https://mumbai.polygonscan.com/tx/0xb1470e0c34729974bee524b9eced35d1d553bd26e184679aa7a9e77c7571884f\"\n}"
                  },
                  "Invoke as a user": {
                    "value": "{\n  \"status\": \"USER_CONSENT_NEEDED\",\n  \"consentToken\": \"CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw==\"\n}"
                  }
                },
                "schema": {
                  "oneOf": [
                    {
                      "title": "Invoke as a developer",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "QUEUED"
                        },
                        "transactionId": {
                          "type": "string",
                          "example": "2d59c2f4-9766-451d-91f2-b7bcb96f51d0"
                        },
                        "transactionHash": {
                          "type": "string",
                          "example": "0xb1470e0c34729974bee524b9eced35d1d553bd26e184679aa7a9e77c7571884f"
                        },
                        "transactionChainScanUrl": {
                          "type": "string",
                          "example": "https://mumbai.polygonscan.com/tx/0xb1470e0c34729974bee524b9eced35d1d553bd26e184679aa7a9e77c7571884f"
                        }
                      }
                    },
                    {
                      "title": "Invoke as a user",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "USER_CONSENT_NEEDED"
                        },
                        "consentToken": {
                          "type": "string",
                          "example": "CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw=="
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
```