LuaScript

Run LuaScript code

The LuaScript policy allows you to execute custom Lua code during API processing. The policy provides extension functions and preset global variables for manipulating assembly context, messages, and variables. For detailed information about available extension functions, see Lua Script extension functions.

Table 1. Supported parameters
Parameter Required Data type Details
actions No object Defines the set of operations or functions to be executed within the Lua script
source Yes string Specifies the Lua script source code or file path that contains the logic to run
Table 2. Options for actions
Options Required Data type Details
authenticate Yes object Authenticate request based on extracted identity
authorize Yes object Authorize access for an authenticated request
azureOpenAiChatCompletions Yes object API Endpoint call for Azure Open AI backend server, POST Chat Completions URI
azureOpenAiEmbeddings Yes object API Endpoint call for Azure Open AI backend server, POST Embeddings URI
azureOpenAiModels Yes object API Endpoint call for Azure Open AI backend server, GET Models URI
azureOpenAiModelsId Yes object API Endpoint call for Azure Open AI backend server, GET Models/{model_id} URI
block Yes object Block a request based on configured criteria
setAuthorization Yes object Sets the Authorization header
cors Yes object Configure gateway support for CORS (Cross-Origin Resource Sharing)
countLimit Yes object Enforce simultaneous access to resources
extractIdentity Yes object Extract the identity
handlebarsTemplate Yes object Generate String value or payload using Handlerbars template
ibmCloudLogin Yes object Login to IBM Cloud using pre-configured credentials
invoke Yes object Call an external endpoint (Currently Http(s))
invokeAwsLambda Yes object Invoke AWS lambda function
loadBalancer Yes object Distribute traffic across multiple endpoints
openAiChatCompletions Yes object API Endpoint call for Open AI backend server, POST Chat Completions URI
openAiEmbeddings Yes object API Endpoint call for Open AI backend server, POST Embeddings URI
openAiModels Yes object API Endpoint call for Open AI backend server, GET Models URI
openAiModelsId Yes object API Endpoint call for Open AI backend server, GET Models/{model_id} URI
parse Yes object Parse the payload of a message
rateLimit Yes object Limit the rate of access to a specified resource
redact Yes object Redact message payload, header, variable, query parameters, and telemetry
remove Yes object Remove message payload, header, variable, query parameters, and telemetry
set Yes object Set specified fields on the Assembly Context
sqlInjectionFilter Yes object Scans payload and/or URI for SQL injection attacks
transform Yes object Transform message payload, header, variable, uri, and telemetry
userDefined Yes object Call into an assembly defined as a separate ConfigMap
validate Yes object Validate request
watsonxModels Yes object API Endpoint call for Watson X backend server, GET Models URI
watsonxTextGen Yes object API Endpoint call for Watson X backend server, POST Text Generation URI
watsonxTokenize Yes object API Endpoint call for Watson X backend server, POST Tokenize URI
geminiModels Yes object API Endpoint call for Gemini backend server, GET Models URI
geminiModelsId Yes object API Endpoint call for Gemini backend server, POST Generate Content URI
geminiGenerateContent Yes object API Endpoint call for Gemini backend server, POST Generate Content URI
geminiEmbedContent Yes object API Endpoint call for Gemini backend server, POST Batch Embeddings URI
geminiBatchEmbedContents Yes object API Endpoint call for Gemini backend server, POST Batch Embeddings URI
geminiCountTokens Yes object API Endpoint call for Gemini backend server, POST Count Tokens URI