Rules

Documentation for Rules

Base path: /api/v1/rules

Rules are decision logic components built using the GoRules JDM (JSON Decision Model) format. They support conditions, decision tables, expressions, and function nodes. Rules go through a draft β†’ version lifecycle similar to workflows.

All endpoints require JWT authentication and an x-active-org header.


Endpoints Overview

MethodPathDescription
POST/api/v1/rules/:threadId/messagesSend a message in a rules chat thread (SSE)
GET/api/v1/rulesList all rules
GET/api/v1/rules/:ruleIdGet rule details
GET/api/v1/rules/:ruleId/versionsList rule versions
POST/api/v1/rulesSave a rule from a draft
POST/api/v1/rules/:ruleId/versionsCreate a new rule version from a draft
POST/api/v1/rules/drafts/:draftId/validateValidate a rule draft
POST/api/v1/rules/drafts/:draftId/testTest a rule draft with inputs

POST /api/v1/rules/:threadId/messages

Sends a message to the AI rules assistant in a chat thread and streams the response via SSE. Used to author/edit decision rule definitions through conversation.

Path Parameters

ParameterTypeDescription
threadIdstring (UUID)Thread ID (must be a rules thread)

Request Body (multipart/form-data)

FieldTypeRequiredDefaultDescription
messagestringYes–User message text
isInterruptbooleanNofalseWhether this is a response to an interrupt
inputsJSON objectNo{}Input values when responding to interrupts
attachmentsFile[]No[]File attachments
modelstringNo"GPT-4o"AI model to use

Available models: GPT-4o, GPT-4o-mini, Claude-3-5-Sonnet, Claude-3-5-Haiku, Gemini-2.0-Flash, Gemini-2.5-Pro, DeepSeek-R1, o3-mini, o4-mini

Response

Returns an SSE stream (Content-Type: text/event-stream).

EventDataDescription
ping{ "content": "ping" }Keep-alive heartbeat
message{ "content": "<text>" }AI response text
error{ "content": "<message>" }Streaming error

GET /api/v1/rules

Lists all rules in the active organization.

Response 200 OK

json

Rule fields:

FieldTypeDescription
idstring (UUID)Rule ID
namestringRule name
descriptionstring | nullRule description
createdAtstring (ISO 8601)Creation time
updatedAtstring (ISO 8601)Last update time

GET /api/v1/rules/:ruleId

Returns details of a specific rule including its current version definition.

Path Parameters

ParameterTypeDescription
ruleIdstring (UUID)Rule ID

Response 200 OK

json

GET /api/v1/rules/:ruleId/versions

Lists all published versions of a rule.

Path Parameters

ParameterTypeDescription
ruleIdstring (UUID)Rule ID

Response 200 OK

json

POST /api/v1/rules

Saves a new rule from a draft. Creates the rule record and its first version.

Request Body (JSON)

FieldTypeRequiredDescription
draftIdstringYesID of the draft to save (thread or rule draft ID)
namestringYesRule name (min length: 1)
descriptionstringNoRule description
json

Response 200 OK

Returns the newly created rule.

Errors

StatusReason
400 Bad RequestDraft is invalid (failed validation)
404 Not FoundDraft not found

POST /api/v1/rules/:ruleId/versions

Creates a new published version of an existing rule from a draft.

Path Parameters

ParameterTypeDescription
ruleIdstring (UUID)Rule ID

Request Body (JSON)

FieldTypeRequiredDescription
draftIdstringYesID of the draft to publish as a new version
json

Response 200 OK

Returns the new rule version.

Errors

StatusReason
400 Bad RequestDraft is invalid
404 Not FoundRule or draft not found

POST /api/v1/rules/drafts/:draftId/validate

Validates a rule draft against the JDM schema. Returns validation errors if any.

Path Parameters

ParameterTypeDescription
draftIdstringDraft ID

Request

No request body required.

Response 200 OK

json

On validation failure:

json

POST /api/v1/rules/drafts/:draftId/test

Runs a rule draft against provided test inputs and returns the output.

Path Parameters

ParameterTypeDescription
draftIdstringDraft ID

Request Body (JSON)

FieldTypeRequiredDescription
inputsobjectYesKey-value input map matching the rule's input schema
json

Response 200 OK

json

Errors

StatusReason
400 Bad RequestDraft is invalid and cannot be executed
404 Not FoundDraft not found

JDM Rule Definition Format

Rules use the GoRules JDM v1 format:

json

Node types: inputNode, outputNode, decisionTableNode, expressionNode, functionNode, switchNode, decisionNode

api-docs/rules