Skip to main content
POST

Authorizations

Authorization
string
header
required

Pass the API key in the Authorization header, You need to put Token keyword before the API key. e.g. 'Authorization: Token '

Body

application/json
name
string
required

Name (1-255 characters), unique in the project. A HELPER macro's name must be an identifier: letters, digits and underscores, not starting with a digit (FunctionMacroHelperNameInvalid), and its code must define {% macro <name>(...) %} with this name. For any macro written as definitions, the one named like the record runs (else the first).

Required string length: 1 - 255
type
enum<string>
required

JAVASCRIPT_FUNCTION: the body of function (text, vars) { ... }. JINJA_MACRO: a Jinja template with text, vars and args in scope, or a {% macro <name>(...) %} definition.

Available options:
JAVASCRIPT_FUNCTION,
JINJA_MACRO
usedAs
enum<string>
required

CHECK: answers "does this text match?" (a guardrail's lookFor). ACTION: answers "what changes?" (a guardrail's behaviour): new text, or variables to set. HELPER: a macro prompts call by its name, as {{ <name>(...) }} (JINJA_MACRO only).

Available options:
CHECK,
ACTION,
HELPER
code
string
required

The code (1-20,000 characters), compiled when you save it.

Function: the body of function (text, vars) { ... }. text is what was said, as said; vars are the call's variables, as text unless a value is JSON. A CHECK returns true to match. An ACTION returns a string (the new text) or an object (the variables to set). JavaScript built-ins only (no console, fetch or timers); 50 ms and 16 MiB per run.

Macro: a template with text, vars and args, or a {% macro <name>(...) %} definition (required for HELPER, named like the record). A CHECK matches unless it renders empty, false, 0, none or no. An ACTION sets variables when it renders a JSON object; anything else is the new text. 50 ms and 64 KiB of output.

Required string length: 1 - 20000
notes
string | null

Your own notes. Not used on calls.

Maximum string length: 2000
params
string[] | null

HELPER macros only, and optional: the parameters that the {% macro <name>(...) %} in code declares, in order. Hamsa reads them from the code; if you send them they must match it (FunctionMacroParamsMismatch). Leave out or null for CHECK and ACTION.

Maximum array length: 20
Maximum string length: 64
Pattern: ^[A-Za-z_][A-Za-z0-9_]*$

Response

Created

success
boolean
Example:

true

message
string
Example:

"success"

data
object

A project script: a guardrail check or action, or a prompt helper macro.