> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agent.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Call Serverless Function

> Execute serverless code directly within workflows for complex operations.



## OpenAPI

````yaml /api-reference/v1/v1.1.0_openapi.json post /action/serverless_function
openapi: 3.0.0
info:
  version: 1.1.0
  title: AI Actions - Get Data
  description: API specifications for 'Get Data' category AI actions.
  license:
    name: MIT
servers:
  - url: https://api-lr.agent.ai/v1
security:
  - bearerAuth: []
paths:
  /action/serverless_function:
    post:
      tags:
        - Workflow & Logic
      summary: Call Serverless Function
      description: >-
        Execute serverless code directly within workflows for complex
        operations.
      operationId: serverlessFunction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                language:
                  type: string
                  enum:
                    - python
                    - node
                  description: >-
                    Select the language for the serverless function, such as
                    'Python' or 'Node'.
                  default: python
                serverless_code:
                  type: string
                  x-ui: textarea
                  description: >-
                    Enter the serverless function code here, using Python or
                    Node syntax to perform specific tasks.
                  default: |
                    import json

                    def lambda_handler(event, context):
                      agent_context = {}
                      
                      # Handle POST requests
                      if event and 'body' in event and event['body']:
                          try:
                              event_json = json.loads(event['body'])
                              agent_context = event_json.get('context', event_json)
                          except json.JSONDecodeError:
                              # Handle case where body isn't valid JSON
                              agent_context = {"error": "Invalid JSON in request body"}
                      
                      # Handle GET requests
                      elif event and 'queryStringParameters' in event and event['queryStringParameters']:
                          agent_context = event['queryStringParameters']
                      
                      # Handle API Gateway format for both
                      elif event and 'pathParameters' in event and event['pathParameters']:
                          agent_context = event['pathParameters']
                      
                      # Prepare response
                      body = {
                          "message": "Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!",
                          "input": event,
                          "context": agent_context
                      }
                      
                      # Include CORS headers for browser access
                      headers = {
                          "Content-Type": "application/json",
                          "Access-Control-Allow-Origin": "*",
                          "Access-Control-Allow-Headers": "Content-Type",
                          "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
                      }
                      
                      response = {
                          "statusCode": 200,
                          "headers": headers,
                          "body": json.dumps(body)
                      }
                      
                      return response
                output_variable_name:
                  type: string
                  description: >-
                    Provide a variable name to store the result of the
                    serverless function, like 'function_result' or
                    'api_response'.
                  pattern: ^[a-zA-Z][a-zA-Z0-9_]*$
              required:
                - language
                - serverless_code
                - output_variable_name
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionResponse'
        '401':
          description: Unauthorized - invalid or missing bearer token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionResponse'
components:
  schemas:
    ActionResponse:
      type: object
      properties:
        status:
          type: integer
          format: int32
          description: HTTP status code of the action response
        response:
          type: object
          description: Response data from the action
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token from your account
        ([https://agent.ai/user/integrations#api](https://agent.ai/user/integrations#api))

````