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 field type description api status code integer http status code of the api response possible values 200 (success), 401 (access denied), 412 (precondition failed), 500 (internal server error) api status message string message indicating the status of the api call (e g , "successful", "llm connectivity issue", "internal server error", "access denied") app prompt string the user's application specific prompt app prompt context string context provided alongside the user's prompt this field is currently an empty string input dictionary details about the input, including guardrails metadata input configuration, number of active and inactive guardrails num tokens number of tokens processed in the input violated policies policies violated, if any, or an empty string latency/sec given user's prompt processing time in sec output dictionary details about the output, including guardrails metadata output configuration, number of active and inactive guardrails num tokens number of tokens processed in the input violated policies policies violated, if any, or an empty string latency/sec llm response processing time in sec metadata dictionary metadata about the api call, including api version api version (e g , v1 5) app name application name event id unique identifier for the api call execution mode mode of operation (e g , block) timestamp time of the api call in gmt redacted prompt string sanitized or redacted version of the user prompt if pii redaction is enabled, or an empty string otherwise siem dictionary security information and event management (siem) details, including active siem list of active siem systems inactive siem list of inactive siem systems status code status code for siem processing possible values 200 (success) , 500 (internal server error), null or empty is not needed to send message to siem status message status message for siem processing (e g , "successful", "internal server error", empty string ) violation exist boolean indicates if any policy violations occurred ( true or false ) violation on string indicates whether the policy violation occurred due to the user's prompt ( input ) or the llm response( output ) 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