<POST> Chat API
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ChatRequest {
public static void main(String[] args) {
try {
String urlString = "{guardian_url}/chat/{app_name}";
String jsonInputString = "{\"prompt\": \"String\"}";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
int code = conn.getResponseCode();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
conn.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println("Response Code: " + code);
System.out.println("Response: " + response.toString());
}
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}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: |
| |
|
| |
|
| |
|
| |
|
output | dictionary | Details about the output, including: |
| |
|
| |
|
| |
|
| |
|
metadata | dictionary | Metadata about the API call, including: |
| |
|
| |
|
| |
|
| |
|
| |
|
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: |
| |
|
| |
|
| |
|
| |
|
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: