AOAI Protocol Alignment Mode API Reference¶
AOAI Protocol Alignment Mode supports only gRPC protocol. This document describes the gRPC protocol for integrating with the RAI platform, detailing the events sent to the service and the events returned by the service. Each event and field is explained in detail.
Events Sent to the Service¶
1. Request Event¶
This event sends a payload to the RAI service for analysis.
Example:
{
"sourceType": "PROMPT",
"apiName": "Chatcompletion",
"payload": "{\"model\":\"gpt-4o\",\"messages\":[{\"role\":\"developer\",\"content\":\"You are a helpful assistant.\"},{\"role\":\"user\",\"content\":\"Hello!\"}]}"
}
Fields:
-
sourceType
(string): The origin of the message. Possible values:PROMPT
COMPLETION
-
apiName
(string): Name of the API being invoked. Example values:Chatcompletion
Realtime
Completion
Imagegeneration
-
payload
(string): The serialized payload of the content, including model and messages.
Events Returned by the Service¶
messageId
andcontentIndex
in returned events¶In this mode, customer didn't specify the
messageId
andcontentIndex
when forward the request payload, we will follow below rules to return themessageId
andcontentIndex
in the returned events.
Completion API and Chat API:
The prompt is collected as a whole payload, with
messageId
andcontentIndex
scoped bysourceType=Prompt
.- For Completion API:
- All prompt text is concatenated into a single string.
- Default:
messageId = "0"
,contentIndex = 0
.- For Chat API:
messageId
is the string index in themessages
array.contentIndex
is the index of content within the message.For LLM completion,
messageId
is the choice index, andcontentIndex
is the array index of content in the choice.Real-Time API Multi-Turn Conversations:
For user inputs:
item_id
asmessageId
.- For model responses:
len(response_id)
+response_id
+len(item_id)
+item_id
definesmessageId
. For example,res_01
anditem_02
is6res_017item_02
.- Content uses its natural indices as
contentIndex
.
1. Analysis Result Event¶
This event represents a partial annotation result for a segment of content.
Example:
{
"analysisResult": {
"offset": {
"sourceType": "PROMPT",
"messageId": "0",
"contentIndex": 0,
"startOffset": 0,
"endOffset": 50
},
"harmCategoryTaskResults": [
{
"result": "OK",
"isBlocking": true,
"kind": "HARM_CATEGORY",
"harmCategoryTaskResult": {
"harmCategory": "HATE",
"isDetected": true,
"severity": 3,
"riskLevel": "HIGH"
}
}
]
}
}
Fields:
-
offset
(object): Specifies the range of content analyzed.sourceType
(string): Same as the inputsourceType
.messageId
(string): Same as the inputmessageId
.contentIndex
(integer): Same as the inputcontentIndex
.startOffset
(integer): UTF-8 start offset for the analyzed content.endOffset
(integer): UTF-8 end offset for the analyzed content.
-
harmCategoryTaskResults
(array): Results for harm category detection tasks.-
result
(string): Indicates the outcome. Possible values:OK
NoModel
-
isBlocking
(boolean): Whether the content is blocked due to harm detection. -
kind
(string): Type of task. Example:HARM_CATEGORY
. -
harmCategoryTaskResult
(object): Details of the harm detection.harmCategory
(string): Type of harm detected (e.g.,HATE
).isDetected
(boolean): Whether harm was detected.severity
(integer): Severity level (1-5).riskLevel
(string): Risk level (e.g.,HIGH
,LOW
).
-
2. Watermark Event¶
This event indicates that content up to a certain offset has been analyzed and found safe.
Example:
Fields:
-
watermark
(object):sourceType
(string): Same as inputsourceType
.messageId
(string): Same as inputmessageId
.contentIndex
(integer): Same as inputcontentIndex
.offset
(integer): Maximum offset analyzed and verified as safe.
3. Completion Event¶
This event indicates that the analysis for the input stream has been completed. Example:
Fields:
-
completion
(object):end_reason
(string): Reason for stream completion. Example:END_REASON_END_OF_STREAM
.error_description
(string): Description of any errors encountered (empty if no errors).
Summary¶
The gRPC protocol facilitates seamless interaction with the RAI platform, providing robust mechanisms for real-time analysis and feedback. The events and fields detailed above serve as a comprehensive guide to understanding and implementing this integration.