Webhookモード
Webhookモード
GPTBotsエージェントは、現在3つのメッセージレスポンスモードに対応しています:blocking
、streaming
、そしてwebhook
モードです。
開発者がwebhookモードを使用してレスポンスメッセージを受信する場合、AIのレスポンスと人によるレスポンスの両方が指定された Webhook URL に送信されます。
レスポンスモード | サポートされるメッセージの種類 |
---|---|
blocking | AIのレスポンス |
streaming | AIのレスポンス |
webhook | AIのレスポンス、人によるレスポンス |
メソッド
POST
呼び出し先(エンドポイントの設定)
「Agent → Integration → API → Webhook」ページにて、あなたのメッセージ受信用URLを設定してください。
認証
認証方法の説明についてはAPI Overviewをご参照ください。
リクエスト
リクエスト例
curl -X POST 'YOUR_API_URL' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"create_time": 1679587005,
"conversation_id": "657303a8a764d47094874bbe",
"message_id": "65a4ccfC7ce58e728d5897e0",
"output": [
{
"from_component_branch": "1",
"from_component_name": "Component Name",
"content": {
"text": "Hi, is there anything I can help you?",
"audio": [
{
"audio": "http://gptbots.ai/example.mp3",
"transcript": "The transcribed content of the audio"
}
]
}
}
],
"usage": {
"tokens": {
"total_tokens": 29,
"prompt_tokens": 19,
"prompt_tokens_details":
{
"audio_tokens": 0,
"text_tokens":0
},
"completion_tokens": 10,
"completion_tokens_details":
{
"reasoning_tokens": 0,
"audio_tokens": 0,
"text_tokens": 0
}
},
"credits": {
"total_credits":0.0, //prompt + completion
"text_input_credits": 0.0,
"text_output_credits": 0.0,
"audio_input_credits": 0.0,
"audio_output_credits": 0.0
}
}
}'
curl -X POST 'YOUR_API_URL' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"create_time": 1679587005,
"conversation_id": "657303a8a764d47094874bbe",
"message_id": "65a4ccfC7ce58e728d5897e0",
"output": [
{
"from_component_branch": "1",
"from_component_name": "Component Name",
"content": {
"text": "Hi, is there anything I can help you?",
"audio": [
{
"audio": "http://gptbots.ai/example.mp3",
"transcript": "The transcribed content of the audio"
}
]
}
}
],
"usage": {
"tokens": {
"total_tokens": 29,
"prompt_tokens": 19,
"prompt_tokens_details":
{
"audio_tokens": 0,
"text_tokens":0
},
"completion_tokens": 10,
"completion_tokens_details":
{
"reasoning_tokens": 0,
"audio_tokens": 0,
"text_tokens": 0
}
},
"credits": {
"total_credits":0.0, //prompt + completion
"text_input_credits": 0.0,
"text_output_credits": 0.0,
"audio_input_credits": 0.0,
"audio_output_credits": 0.0
}
}
}'
このコードブロックをポップアップで表示
リクエストヘッダー
フィールド | タイプ | 説明 |
---|---|---|
Authorization | Bearer ${API Key} | 認証には Authorization: Bearer ${API Key} を使用してください。トークンはAPIキーページから取得できます。 |
Content-Type | application/json | データの形式は application/json を設定してください。 |
リクエストボディ
フィールド | タイプ | 説明 |
---|---|---|
conversation_id | String | 会話の一意な識別子です。 |
message_id | String | 会話内の特定メッセージの一意な識別子です。 |
create_time | Long | このメッセージが生成されたタイムスタンプです。 |
output | JSON Array | AIエージェントの出力内容です。 |
from_component_branch | String | フローエージェントの分岐名です。 |
from_component_name | String | フローエージェントにおける上流コンポーネント名です。 |
content | Object | エージェントの返信内容。現在はtext と audio の2種類をサポートしています。 |
usage | Object | 使用量に関する情報です。 |
tokens | JSON Array | この対話で消費されたトークンの合計です。 |
total_tokens | Integer | 入力と出力を含めた総トークン数です。 |
prompt_tokens | Integer | 入力に使用されたトークン数です。 |
completion_tokens | Integer | 出力に使用されたトークン数です。 |
prompt_tokens_details | Object | 入力におけるトークン消費の内訳です。 |
completion_tokens_details | Object | 出力におけるトークン消費の内訳です。 |
credits | Object | この対話で消費されたクレジットの情報です。 |
text_input_credits | Double | テキスト入力メッセージに使用されたクレジット数です。 |
text_output_credits | Double | テキスト出力メッセージに使用されたクレジット数です。 |
audio_input_credits | Double | 音声入力メッセージに使用されたクレジット数です。 |
audio_output_credits | Double | 音声出力メッセージに使用されたクレジット数です。 |
レスポンス
レスポンス例
{
"code": 200,
"msg": "success"
}
{
"code": 200,
"msg": "success"
}
このコードブロックをポップアップで表示