---
title: <POST> Chat API
slug: lesspostgreater-chat-api
docTags: 
createdAt: 2024-08-20T12:08:10.572Z
---

:::ApiMethodV2
```json
{
  "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 &#x20;**      | **Type&#x20;** | **Description&#x20;**                                                                                                                                                        |
| --------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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").<br />                                |
| `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&#x20;                                                                                                                                         |
|                       |                | - `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:

::githubGist{url="https://gist.github.com/7fb4cfabca8ed7df3ad33674a9d8b32b.js"}

