Conditions
Create condition
POST
/
automation
/
conditions
/
Create Condition
curl --request POST \
--url https://api.keywordsai.co/automation/conditions/ \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.keywordsai.co/automation/conditions/"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.keywordsai.co/automation/conditions/', 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.keywordsai.co/automation/conditions/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.keywordsai.co/automation/conditions/"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
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.keywordsai.co/automation/conditions/")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.keywordsai.co/automation/conditions/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "cond-12345",
"name": "Successful Requests",
"condition_slug": "success_logs",
"condition_type": "single_log",
"description": "Matches logs with HTTP status code 200",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
},
"unique_organization_id": "org-abc123",
"created_at": "2025-01-15T10:00:00Z",
"updated_at": "2025-01-15T10:00:00Z"
}
Creates a new automation condition that defines which logs should trigger evaluations.
Note: Use your API Key (not JWT token) for all requests. You can find your API keys in the Keywords AI platform under Settings > API Keys.
Authentication
All endpoints require API key authentication:Authorization: Bearer YOUR_API_KEY
Required Fields
| Field | Type | Description |
|---|---|---|
name | string | Display name for the condition |
condition_slug | string | Unique identifier for the condition |
condition_type | string | Must be "single_log" for online eval |
condition_policy | object | JSON structure defining evaluation rules |
Optional Fields
| Field | Type | Description |
|---|---|---|
description | string | Description of the condition |
Condition Policy Structure
Thecondition_policy object contains:
rules(array): Array of rule objects, each with:field(string): Field to evaluate (e.g.,"status_code","latency","model")operator(string): Comparison operator (see available operators below)value(any): Value to compare against
connector(string): How to combine rules ("AND"or"OR")
Available Operators
equals,not_equalsgreater_than,less_than,greater_than_or_equal,less_than_or_equalcontains,not_containsin,not_in
Available Fields
status_code: HTTP status codelatency: Request latency in secondstotal_tokens: Total token countinput_tokens: Input token countoutput_tokens: Output token countcost: Request costmodel: Model name- Any custom metadata field
Examples
Single Rule Condition
import requests
url = "https://api.keywordsai.co/automation/conditions/"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"name": "Successful Requests",
"condition_slug": "success_logs",
"condition_type": "single_log",
"description": "Matches logs with HTTP status code 200",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://api.keywordsai.co/automation/conditions/" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Successful Requests",
"condition_slug": "success_logs",
"condition_type": "single_log",
"description": "Matches logs with HTTP status code 200",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
}
}'
Multiple Rules Condition
data = {
"name": "High Latency Errors",
"condition_slug": "high_latency_errors",
"condition_type": "single_log",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "greater_than_or_equal",
"value": 500
},
{
"field": "latency",
"operator": "greater_than",
"value": 2.0
}
],
"connector": "AND"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://api.keywordsai.co/automation/conditions/" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "High Latency Errors",
"condition_slug": "high_latency_errors",
"condition_type": "single_log",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "greater_than_or_equal",
"value": 500
},
{
"field": "latency",
"operator": "greater_than",
"value": 2.0
}
],
"connector": "AND"
}
}'
Condition with Custom Metadata Field
data = {
"name": "VIP Customer Requests",
"condition_slug": "vip_customer_logs",
"condition_type": "single_log",
"condition_policy": {
"rules": [
{
"field": "metadata.customer_tier",
"operator": "equals",
"value": "VIP"
},
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://api.keywordsai.co/automation/conditions/" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "VIP Customer Requests",
"condition_slug": "vip_customer_logs",
"condition_type": "single_log",
"condition_policy": {
"rules": [
{
"field": "metadata.customer_tier",
"operator": "equals",
"value": "VIP"
},
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
}
}'
Response
Status: 201 Created{
"id": "cond-12345",
"name": "Successful Requests",
"condition_slug": "success_logs",
"condition_type": "single_log",
"description": "Matches logs with HTTP status code 200",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
},
"unique_organization_id": "org-abc123",
"created_at": "2025-01-15T10:00:00Z",
"updated_at": "2025-01-15T10:00:00Z"
}
Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique condition identifier (save this for creating automations) |
name | string | Display name of the condition |
condition_slug | string | URL-friendly identifier |
condition_type | string | Type of condition ("single_log") |
description | string | Description of the condition |
condition_policy | object | The condition policy with rules and connector |
unique_organization_id | string | Organization identifier |
created_at | string | ISO timestamp of creation |
updated_at | string | ISO timestamp of last update |
Error Responses
400 Bad Request
{
"condition_policy": [
"Invalid operator 'invalid_op' for field 'status_code'"
]
}
401 Unauthorized
{
"detail": "Authentication credentials were not provided."
}
422 Unprocessable Entity
{
"condition_type": [
"Condition type must be 'single_log' for online evaluation automations"
]
}
Was this page helpful?
⌘I
Create Condition
curl --request POST \
--url https://api.keywordsai.co/automation/conditions/ \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.keywordsai.co/automation/conditions/"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.keywordsai.co/automation/conditions/', 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.keywordsai.co/automation/conditions/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.keywordsai.co/automation/conditions/"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
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.keywordsai.co/automation/conditions/")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.keywordsai.co/automation/conditions/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "cond-12345",
"name": "Successful Requests",
"condition_slug": "success_logs",
"condition_type": "single_log",
"description": "Matches logs with HTTP status code 200",
"condition_policy": {
"rules": [
{
"field": "status_code",
"operator": "equals",
"value": 200
}
],
"connector": "AND"
},
"unique_organization_id": "org-abc123",
"created_at": "2025-01-15T10:00:00Z",
"updated_at": "2025-01-15T10:00:00Z"
}