Call Serverless Function
curl --request POST \
--url https://api-lr.agent.ai/v1/action/serverless_function \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"language": "python",
"serverless_code": "import json\n\ndef lambda_handler(event, context):\n agent_context = {}\n \n # Handle POST requests\n if event and 'body' in event and event['body']:\n try:\n event_json = json.loads(event['body'])\n agent_context = event_json.get('context', event_json)\n except json.JSONDecodeError:\n # Handle case where body isn't valid JSON\n agent_context = {\"error\": \"Invalid JSON in request body\"}\n \n # Handle GET requests\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\n agent_context = event['queryStringParameters']\n \n # Handle API Gateway format for both\n elif event and 'pathParameters' in event and event['pathParameters']:\n agent_context = event['pathParameters']\n \n # Prepare response\n body = {\n \"message\": \"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\",\n \"input\": event,\n \"context\": agent_context\n }\n \n # Include CORS headers for browser access\n headers = {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET\"\n }\n \n response = {\n \"statusCode\": 200,\n \"headers\": headers,\n \"body\": json.dumps(body)\n }\n \n return response\n",
"output_variable_name": "<string>"
}
EOFimport requests
url = "https://api-lr.agent.ai/v1/action/serverless_function"
payload = {
"language": "python",
"serverless_code": "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": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
language: 'python',
serverless_code: 'import json\n\ndef lambda_handler(event, context):\n agent_context = {}\n \n # Handle POST requests\n if event and \'body\' in event and event[\'body\']:\n try:\n event_json = json.loads(event[\'body\'])\n agent_context = event_json.get(\'context\', event_json)\n except json.JSONDecodeError:\n # Handle case where body isn\'t valid JSON\n agent_context = {"error": "Invalid JSON in request body"}\n \n # Handle GET requests\n elif event and \'queryStringParameters\' in event and event[\'queryStringParameters\']:\n agent_context = event[\'queryStringParameters\']\n \n # Handle API Gateway format for both\n elif event and \'pathParameters\' in event and event[\'pathParameters\']:\n agent_context = event[\'pathParameters\']\n \n # Prepare response\n body = {\n "message": "Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!",\n "input": event,\n "context": agent_context\n }\n \n # Include CORS headers for browser access\n headers = {\n "Content-Type": "application/json",\n "Access-Control-Allow-Origin": "*",\n "Access-Control-Allow-Headers": "Content-Type",\n "Access-Control-Allow-Methods": "OPTIONS,POST,GET"\n }\n \n response = {\n "statusCode": 200,\n "headers": headers,\n "body": json.dumps(body)\n }\n \n return response\n',
output_variable_name: '<string>'
})
};
fetch('https://api-lr.agent.ai/v1/action/serverless_function', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-lr.agent.ai/v1/action/serverless_function",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'language' => 'python',
'serverless_code' => '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' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-lr.agent.ai/v1/action/serverless_function"
payload := strings.NewReader("{\n \"language\": \"python\",\n \"serverless_code\": \"import json\\n\\ndef lambda_handler(event, context):\\n agent_context = {}\\n \\n # Handle POST requests\\n if event and 'body' in event and event['body']:\\n try:\\n event_json = json.loads(event['body'])\\n agent_context = event_json.get('context', event_json)\\n except json.JSONDecodeError:\\n # Handle case where body isn't valid JSON\\n agent_context = {\\\"error\\\": \\\"Invalid JSON in request body\\\"}\\n \\n # Handle GET requests\\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\\n agent_context = event['queryStringParameters']\\n \\n # Handle API Gateway format for both\\n elif event and 'pathParameters' in event and event['pathParameters']:\\n agent_context = event['pathParameters']\\n \\n # Prepare response\\n body = {\\n \\\"message\\\": \\\"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\\\",\\n \\\"input\\\": event,\\n \\\"context\\\": agent_context\\n }\\n \\n # Include CORS headers for browser access\\n headers = {\\n \\\"Content-Type\\\": \\\"application/json\\\",\\n \\\"Access-Control-Allow-Origin\\\": \\\"*\\\",\\n \\\"Access-Control-Allow-Headers\\\": \\\"Content-Type\\\",\\n \\\"Access-Control-Allow-Methods\\\": \\\"OPTIONS,POST,GET\\\"\\n }\\n \\n response = {\\n \\\"statusCode\\\": 200,\\n \\\"headers\\\": headers,\\n \\\"body\\\": json.dumps(body)\\n }\\n \\n return response\\n\",\n \"output_variable_name\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-lr.agent.ai/v1/action/serverless_function")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"language\": \"python\",\n \"serverless_code\": \"import json\\n\\ndef lambda_handler(event, context):\\n agent_context = {}\\n \\n # Handle POST requests\\n if event and 'body' in event and event['body']:\\n try:\\n event_json = json.loads(event['body'])\\n agent_context = event_json.get('context', event_json)\\n except json.JSONDecodeError:\\n # Handle case where body isn't valid JSON\\n agent_context = {\\\"error\\\": \\\"Invalid JSON in request body\\\"}\\n \\n # Handle GET requests\\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\\n agent_context = event['queryStringParameters']\\n \\n # Handle API Gateway format for both\\n elif event and 'pathParameters' in event and event['pathParameters']:\\n agent_context = event['pathParameters']\\n \\n # Prepare response\\n body = {\\n \\\"message\\\": \\\"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\\\",\\n \\\"input\\\": event,\\n \\\"context\\\": agent_context\\n }\\n \\n # Include CORS headers for browser access\\n headers = {\\n \\\"Content-Type\\\": \\\"application/json\\\",\\n \\\"Access-Control-Allow-Origin\\\": \\\"*\\\",\\n \\\"Access-Control-Allow-Headers\\\": \\\"Content-Type\\\",\\n \\\"Access-Control-Allow-Methods\\\": \\\"OPTIONS,POST,GET\\\"\\n }\\n \\n response = {\\n \\\"statusCode\\\": 200,\\n \\\"headers\\\": headers,\\n \\\"body\\\": json.dumps(body)\\n }\\n \\n return response\\n\",\n \"output_variable_name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-lr.agent.ai/v1/action/serverless_function")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"language\": \"python\",\n \"serverless_code\": \"import json\\n\\ndef lambda_handler(event, context):\\n agent_context = {}\\n \\n # Handle POST requests\\n if event and 'body' in event and event['body']:\\n try:\\n event_json = json.loads(event['body'])\\n agent_context = event_json.get('context', event_json)\\n except json.JSONDecodeError:\\n # Handle case where body isn't valid JSON\\n agent_context = {\\\"error\\\": \\\"Invalid JSON in request body\\\"}\\n \\n # Handle GET requests\\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\\n agent_context = event['queryStringParameters']\\n \\n # Handle API Gateway format for both\\n elif event and 'pathParameters' in event and event['pathParameters']:\\n agent_context = event['pathParameters']\\n \\n # Prepare response\\n body = {\\n \\\"message\\\": \\\"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\\\",\\n \\\"input\\\": event,\\n \\\"context\\\": agent_context\\n }\\n \\n # Include CORS headers for browser access\\n headers = {\\n \\\"Content-Type\\\": \\\"application/json\\\",\\n \\\"Access-Control-Allow-Origin\\\": \\\"*\\\",\\n \\\"Access-Control-Allow-Headers\\\": \\\"Content-Type\\\",\\n \\\"Access-Control-Allow-Methods\\\": \\\"OPTIONS,POST,GET\\\"\\n }\\n \\n response = {\\n \\\"statusCode\\\": 200,\\n \\\"headers\\\": headers,\\n \\\"body\\\": json.dumps(body)\\n }\\n \\n return response\\n\",\n \"output_variable_name\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": 123,
"response": {}
}{
"status": 123,
"response": {}
}{
"status": 123,
"response": {}
}{
"status": 123,
"response": {}
}Workflow & Logic
Call Serverless Function
Execute serverless code directly within workflows for complex operations.
POST
/
action
/
serverless_function
Call Serverless Function
curl --request POST \
--url https://api-lr.agent.ai/v1/action/serverless_function \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"language": "python",
"serverless_code": "import json\n\ndef lambda_handler(event, context):\n agent_context = {}\n \n # Handle POST requests\n if event and 'body' in event and event['body']:\n try:\n event_json = json.loads(event['body'])\n agent_context = event_json.get('context', event_json)\n except json.JSONDecodeError:\n # Handle case where body isn't valid JSON\n agent_context = {\"error\": \"Invalid JSON in request body\"}\n \n # Handle GET requests\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\n agent_context = event['queryStringParameters']\n \n # Handle API Gateway format for both\n elif event and 'pathParameters' in event and event['pathParameters']:\n agent_context = event['pathParameters']\n \n # Prepare response\n body = {\n \"message\": \"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\",\n \"input\": event,\n \"context\": agent_context\n }\n \n # Include CORS headers for browser access\n headers = {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET\"\n }\n \n response = {\n \"statusCode\": 200,\n \"headers\": headers,\n \"body\": json.dumps(body)\n }\n \n return response\n",
"output_variable_name": "<string>"
}
EOFimport requests
url = "https://api-lr.agent.ai/v1/action/serverless_function"
payload = {
"language": "python",
"serverless_code": "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": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
language: 'python',
serverless_code: 'import json\n\ndef lambda_handler(event, context):\n agent_context = {}\n \n # Handle POST requests\n if event and \'body\' in event and event[\'body\']:\n try:\n event_json = json.loads(event[\'body\'])\n agent_context = event_json.get(\'context\', event_json)\n except json.JSONDecodeError:\n # Handle case where body isn\'t valid JSON\n agent_context = {"error": "Invalid JSON in request body"}\n \n # Handle GET requests\n elif event and \'queryStringParameters\' in event and event[\'queryStringParameters\']:\n agent_context = event[\'queryStringParameters\']\n \n # Handle API Gateway format for both\n elif event and \'pathParameters\' in event and event[\'pathParameters\']:\n agent_context = event[\'pathParameters\']\n \n # Prepare response\n body = {\n "message": "Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!",\n "input": event,\n "context": agent_context\n }\n \n # Include CORS headers for browser access\n headers = {\n "Content-Type": "application/json",\n "Access-Control-Allow-Origin": "*",\n "Access-Control-Allow-Headers": "Content-Type",\n "Access-Control-Allow-Methods": "OPTIONS,POST,GET"\n }\n \n response = {\n "statusCode": 200,\n "headers": headers,\n "body": json.dumps(body)\n }\n \n return response\n',
output_variable_name: '<string>'
})
};
fetch('https://api-lr.agent.ai/v1/action/serverless_function', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-lr.agent.ai/v1/action/serverless_function",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'language' => 'python',
'serverless_code' => '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' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-lr.agent.ai/v1/action/serverless_function"
payload := strings.NewReader("{\n \"language\": \"python\",\n \"serverless_code\": \"import json\\n\\ndef lambda_handler(event, context):\\n agent_context = {}\\n \\n # Handle POST requests\\n if event and 'body' in event and event['body']:\\n try:\\n event_json = json.loads(event['body'])\\n agent_context = event_json.get('context', event_json)\\n except json.JSONDecodeError:\\n # Handle case where body isn't valid JSON\\n agent_context = {\\\"error\\\": \\\"Invalid JSON in request body\\\"}\\n \\n # Handle GET requests\\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\\n agent_context = event['queryStringParameters']\\n \\n # Handle API Gateway format for both\\n elif event and 'pathParameters' in event and event['pathParameters']:\\n agent_context = event['pathParameters']\\n \\n # Prepare response\\n body = {\\n \\\"message\\\": \\\"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\\\",\\n \\\"input\\\": event,\\n \\\"context\\\": agent_context\\n }\\n \\n # Include CORS headers for browser access\\n headers = {\\n \\\"Content-Type\\\": \\\"application/json\\\",\\n \\\"Access-Control-Allow-Origin\\\": \\\"*\\\",\\n \\\"Access-Control-Allow-Headers\\\": \\\"Content-Type\\\",\\n \\\"Access-Control-Allow-Methods\\\": \\\"OPTIONS,POST,GET\\\"\\n }\\n \\n response = {\\n \\\"statusCode\\\": 200,\\n \\\"headers\\\": headers,\\n \\\"body\\\": json.dumps(body)\\n }\\n \\n return response\\n\",\n \"output_variable_name\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-lr.agent.ai/v1/action/serverless_function")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"language\": \"python\",\n \"serverless_code\": \"import json\\n\\ndef lambda_handler(event, context):\\n agent_context = {}\\n \\n # Handle POST requests\\n if event and 'body' in event and event['body']:\\n try:\\n event_json = json.loads(event['body'])\\n agent_context = event_json.get('context', event_json)\\n except json.JSONDecodeError:\\n # Handle case where body isn't valid JSON\\n agent_context = {\\\"error\\\": \\\"Invalid JSON in request body\\\"}\\n \\n # Handle GET requests\\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\\n agent_context = event['queryStringParameters']\\n \\n # Handle API Gateway format for both\\n elif event and 'pathParameters' in event and event['pathParameters']:\\n agent_context = event['pathParameters']\\n \\n # Prepare response\\n body = {\\n \\\"message\\\": \\\"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\\\",\\n \\\"input\\\": event,\\n \\\"context\\\": agent_context\\n }\\n \\n # Include CORS headers for browser access\\n headers = {\\n \\\"Content-Type\\\": \\\"application/json\\\",\\n \\\"Access-Control-Allow-Origin\\\": \\\"*\\\",\\n \\\"Access-Control-Allow-Headers\\\": \\\"Content-Type\\\",\\n \\\"Access-Control-Allow-Methods\\\": \\\"OPTIONS,POST,GET\\\"\\n }\\n \\n response = {\\n \\\"statusCode\\\": 200,\\n \\\"headers\\\": headers,\\n \\\"body\\\": json.dumps(body)\\n }\\n \\n return response\\n\",\n \"output_variable_name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-lr.agent.ai/v1/action/serverless_function")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"language\": \"python\",\n \"serverless_code\": \"import json\\n\\ndef lambda_handler(event, context):\\n agent_context = {}\\n \\n # Handle POST requests\\n if event and 'body' in event and event['body']:\\n try:\\n event_json = json.loads(event['body'])\\n agent_context = event_json.get('context', event_json)\\n except json.JSONDecodeError:\\n # Handle case where body isn't valid JSON\\n agent_context = {\\\"error\\\": \\\"Invalid JSON in request body\\\"}\\n \\n # Handle GET requests\\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\\n agent_context = event['queryStringParameters']\\n \\n # Handle API Gateway format for both\\n elif event and 'pathParameters' in event and event['pathParameters']:\\n agent_context = event['pathParameters']\\n \\n # Prepare response\\n body = {\\n \\\"message\\\": \\\"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\\\",\\n \\\"input\\\": event,\\n \\\"context\\\": agent_context\\n }\\n \\n # Include CORS headers for browser access\\n headers = {\\n \\\"Content-Type\\\": \\\"application/json\\\",\\n \\\"Access-Control-Allow-Origin\\\": \\\"*\\\",\\n \\\"Access-Control-Allow-Headers\\\": \\\"Content-Type\\\",\\n \\\"Access-Control-Allow-Methods\\\": \\\"OPTIONS,POST,GET\\\"\\n }\\n \\n response = {\\n \\\"statusCode\\\": 200,\\n \\\"headers\\\": headers,\\n \\\"body\\\": json.dumps(body)\\n }\\n \\n return response\\n\",\n \"output_variable_name\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": 123,
"response": {}
}{
"status": 123,
"response": {}
}{
"status": 123,
"response": {}
}{
"status": 123,
"response": {}
}Authorizations
Bearer token from your account (https://agent.ai/user/integrations#api)
Body
application/json
Select the language for the serverless function, such as 'Python' or 'Node'.
Available options:
python, node serverless_code
string
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
required
Enter the serverless function code here, using Python or Node syntax to perform specific tasks.
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_]*$⌘I

