API Documentation
Guardian
<POST> Chat API
3 min
{ "name" "chat api", "method" "post", "url" "{guardian url}/chat", "description" "\nthe chat api processes user prompts according to the specified execution mode and returns a detailed response, including application metadata, guardrail configurations, token usage, and policy compliance checks \n", "tab" "examples", "examples" { "languages" \[ { "id" "t sm4okemx4zylnrqasjg", "language" "curl", "code" "curl location globoff '{guardian url}/chat/{app name}' \\\\\n header 'accept application/json' \\\\\n header 'content type application/json' \\\\\n data '{\\"prompt\\" \\"string\\"}'", "customlabel" "" }, { "id" "z7kqwo0jqzbmzmpabsmum", "language" "python", "code" "import requests\nimport json\n\nurl = \\"{guardian url}/chat/{app name}\\"\n\npayload = json dumps({\n \\"prompt\\" \\"string\\"\n})\nheaders = {\n 'accept' 'application/json',\n 'content type' 'application/json'\n}\n\nresponse = requests request(\\"post\\", url, headers=headers, data=payload)\n\nprint(response text)\n", "customlabel" "" }, { "id" "kzajp76oihxq7watevlr6", "language" "java", "code" "import java io outputstream;\nimport java io inputstreamreader;\nimport java io bufferedreader;\nimport java net httpurlconnection;\nimport java net url;\n \npublic class chatrequest {\n public static void main(string\[] args) {\n try {\n \n string urlstring = \\"{guardian url}/chat/{app name}\\";\n string jsoninputstring = \\"{\\\\\\"prompt\\\\\\" \\\\\\"string\\\\\\"}\\";\n \n url url = new url(urlstring);\n\n httpurlconnection conn = (httpurlconnection) url openconnection();\n \n conn setrequestmethod(\\"post\\");\n conn setrequestproperty(\\"accept\\", \\"application/json\\");\n conn setrequestproperty(\\"content type\\", \\"application/json\\");\n conn setdooutput(true);\n \n \n try (outputstream os = conn getoutputstream()) {\n byte\[] input = jsoninputstring getbytes(\\"utf 8\\");\n os write(input, 0, input length);\n }\n \n int code = conn getresponsecode();\n try (bufferedreader br = new bufferedreader(new inputstreamreader(\n conn getinputstream(), \\"utf 8\\"))) {\n stringbuilder response = new stringbuilder();\n string responseline;\n while ((responseline = br readline()) != null) {\n response append(responseline trim());\n }\n system out println(\\"response code \\" + code);\n system out println(\\"response \\" + response tostring());\n }\n \n conn disconnect();\n \n } catch (exception e) {\n e printstacktrace();\n }\n }\n}", "customlabel" "" } ], "selectedlanguageid" "kzajp76oihxq7watevlr6" }, "results" { "languages" \[ { "id" "2jq0g0qizqscdm0ft1w9p", "language" "200", "customlabel" "", "code" "{\n \\"api status code\\" 200,\n \\"api status message\\" \\"successful\\",\n \\"app prompt\\" \\"user prompt\\",\n \\"app prompt context\\" \\"\\",\n \\"input\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {input configuration dict},\n \\"number of active guardrails\\" number of input active guardrails,\n \\"number of inactive guardrails\\" number of input inactive guardrails\n },\n \\"num tokens\\" number of input tokens,\n \\"violated policies\\" \\"comma separated violated policies\\",\n \\"latency/sec\\" 0\n },\n \\"llm response\\" \\"generated llm response based on the user prompt \\",\n \\"metadata\\" {\n \\"api version\\" \\"v1 5\\",\n \\"app name\\" \\"application name\\",\n \\"event id\\" \\"unique id for the user prompt\\",\n \\"execution mode\\" \\"block\\",\n \\"timestamp\\" \\"timestamp user has been created\\"\n },\n \\"output\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {output configuration dict},\n \\"number of active guardrails\\" number of output active guardrails,\n \\"number of inactive guardrails\\" number of output inactive guardrails\n },\n \\"num tokens\\" number of output tokens,\n \\"violated policies\\" \\"comma separated violated policies\\",\n \\"latency/sec\\" 0\n },\n \\"redacted prompt\\" \\"\\",\n \\"siem\\" {\n \\"active siem\\" \[list of active siems],\n \\"inactive siem\\" \[list of inactive siems],\n \\"status code\\" 200,\n \\"status message\\" \\"successful\\"\n },\n \\"violation exist\\" false,\n \\"violation on\\" \\"input or output or empty string\\"\n}" }, { "id" "cgqlckmiwe0qggwt3hc6z", "language" "401", "code" "{\n \\"api status code\\" 401,\n \\"api status message\\" \\"access denied\\",\n \\"app prompt\\" \\"user prompt\\",\n \\"app prompt context\\" \\"\\",\n \\"input\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {},\n \\"number of active guardrails\\" 0,\n \\"number of inactive guardrails\\" 0\n },\n \\"num tokens\\" 0,\n \\"violated policies\\" \\"\\",\n \\"latency/sec\\" 0\n },\n \\"llm response\\" \\"\\",\n \\"metadata\\" {\n \\"api version\\" \\"v1 5\\",\n \\"app name\\" \\"application name\\",\n \\"event id\\" \\"unique id for the user prompt\\",\n \\"execution mode\\" \\"block\\",\n \\"timestamp\\" \\"timestamp user has been created\\"\n },\n \\"output\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {},\n \\"number of active guardrails\\" 0,\n \\"number of inactive guardrails\\" 0\n },\n \\"num tokens\\" 0,\n \\"violated policies\\" \\"\\",\n \\"latency/sec\\" 0\n },\n \\"redacted prompt\\" \\"\\",\n \\"siem\\" {\n \\"active siem\\" \[],\n \\"inactive siem\\" \[],\n \\"status code\\" null,\n \\"status message\\" \\"\\"\n },\n \\"violation exist\\" false,\n \\"violation on\\" \\"\\"\n}", "customlabel" "" }, { "id" "ue 6rdnkkhmtdt cbfj", "language" "429", "code" "{\n \\"api status code\\" 429,\n \\"api status message\\" \\"llm connectivity issue\\",\n \\"app prompt\\" \\"user prompt\\",\n \\"app prompt context\\" \\"\\",\n \\"input\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {input configuration dict},\n \\"number of active guardrails\\" number of input active guardrails,\n \\"number of inactive guardrails\\" number of input inactive guardrails\n },\n \\"num tokens\\" number of input tokens,\n \\"violated policies\\" \\"comma separated violated policies\\",\n \\"latency/sec\\" 0\n },\n \\"llm response\\" \\"\\",\n \\"metadata\\" {\n \\"api version\\" \\"v1 5\\",\n \\"app name\\" \\"application name\\",\n \\"event id\\" \\"unique id for the user prompt\\",\n \\"execution mode\\" \\"block\\",\n \\"timestamp\\" \\"timestamp user has been created\\"\n },\n \\"output\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {},\n \\"number of active guardrails\\" 0,\n \\"number of inactive guardrails\\" 0\n },\n \\"num tokens\\" 0,\n \\"violated policies\\" \\"\\",\n \\"latency/sec\\" 0\n },\n \\"redacted prompt\\" \\"\\",\n \\"siem\\" {\n \\"active siem\\" \[],\n \\"inactive siem\\" \[],\n \\"status code\\" null,\n \\"status message\\" \\"\\"\n },\n \\"violation exist\\" false,\n \\"violation on\\" \\"\\"\n}", "customlabel" "" }, { "id" "vpq7x5yrfnfryclhevio ", "language" "500", "code" "{\n \\"api status code\\" 500,\n \\"api status message\\" \\"internal server error\\",\n \\"app prompt\\" \\"user prompt\\",\n \\"app prompt context\\" \\"\\",\n \\"input\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {},\n \\"number of active guardrails\\" 0,\n \\"number of inactive guardrails\\" 0\n },\n \\"num tokens\\" 0,\n \\"violated policies\\" \\"\\",\n \\"latency/sec\\" 0\n },\n \\"llm response\\" \\"\\",\n \\"metadata\\" {\n \\"api version\\" \\"v1 5\\",\n \\"app name\\" \\"\\",\n \\"event id\\" \\"\\",\n \\"execution mode\\" \\"block\\",\n \\"timestamp\\" \\"\\"\n },\n \\"output\\" {\n \\"guardrails metadata\\" {\n \\"configuration\\" {},\n \\"number of active guardrails\\" 0,\n \\"number of inactive guardrails\\" 0\n },\n \\"num tokens\\" 0,\n \\"violated policies\\" \\"\\",\n \\"latency/sec\\" 0\n },\n \\"redacted prompt\\" \\"\\",\n \\"siem\\" {\n \\"active siem\\" \[],\n \\"inactive siem\\" \[],\n \\"status code\\" null,\n \\"status message\\" \\"\\"\n },\n \\"violation exist\\" false,\n \\"violation on\\" \\"\\"\n}", "customlabel" "" } ], "selectedlanguageid" "2jq0g0qizqscdm0ft1w9p" }, "request" { "pathparameters" \[ { "name" "app name", "kind" "required", "type" "string", "description" "specifies the application endpoint for inference possible values app1, app2, app3 \n", "children" \[] } ], "queryparameters" \[], "headerparameters" \[], "bodydataparameters" \[ { "name" "prompt", "kind" "required", "type" "string", "description" "the user's input or query to be processed by the api \n" } ], "formdataparameters" \[] }, "currentnewparameter" { "label" "path parameter", "value" "pathparameters" }, "response" \[], "hastryitout" true } response field definitions the table below provides a comprehensive breakdown of all the fields included in the api response it describes each field's purpose, type, and possible values to help you understand how to interpret the api's output effectively true 0 204left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type left unhandled content type unhandled content type left unhandled content type connecting to the chat api this below gist provides a detailed example of how to connect to the chat api, including how to structure the request, handle the response, and customize the api call based on your specific needs to get started with integrating the chat api , you can refer to the following github gist for a step by step guide and example code

