チャットメッセージを送信
チャットアプリケーションにリクエストを送信します。
curl --request POST \
--url https://{api_base_url}/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"inputs": {
"city": "San Francisco"
},
"query": "What are the specs of the iPhone 13 Pro Max?",
"response_mode": "streaming",
"conversation_id": "",
"user": "abc-123",
"files": [
{
"type": "image",
"transfer_method": "remote_url",
"url": "https://cloud.dify.ai/logo/logo-site.png"
}
]
}
'{
"event": "message",
"task_id": "c3800678-a077-43df-a102-53f23ed20b88",
"id": "b01a39de-3480-4f3e-9f1e-4841a80f8e5e",
"message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"mode": "chat",
"answer": "iPhone 13 Pro Max specs are listed here:...",
"metadata": {
"usage": {
"prompt_tokens": 1033,
"prompt_unit_price": "0.001",
"prompt_price_unit": "0.001",
"prompt_price": "0.0010330",
"completion_tokens": 128,
"completion_unit_price": "0.002",
"completion_price_unit": "0.001",
"completion_price": "0.0002560",
"total_tokens": 1161,
"total_price": "0.0012890",
"currency": "USD",
"latency": 0.7682376249867957
},
"retriever_resources": [
{
"position": 1,
"dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
"dataset_name": "iPhone",
"document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
"document_name": "iPhone List",
"segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
"score": 0.98457545,
"content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\" \"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
}
]
},
"created_at": 1705407629
}Authorizations
API Key 認証です。すべての API リクエストにおいて、Authorization HTTP ヘッダーに Bearer プレフィックスを付けた API Key を含めてください。例:Authorization: Bearer {API_KEY}。API Key はサーバーサイドに保存し、クライアントサイドで共有・保存しないことを強く推奨します。API Key の漏洩は深刻な結果につながる可能性があります。
Body
チャットメッセージを送信するためのリクエストボディ。
ユーザーの入力/質問内容です。
アプリで定義されたさまざまな変数の値を入力できます。キーと値のペアを含みます。アプリが期待する変数名と型については、アプリケーションのパラメータ情報を取得 レスポンスの user_input_form フィールドを参照してください。
アプリケーション内で一意のユーザー識別子です。この識別子はデータアクセスの範囲を限定します——会話、メッセージ、ファイルは同じ user 値でクエリした場合にのみ表示されます。
レスポンスの返却モードです。streaming(推奨)は SSE を使用します。blocking は完了後に返します(長時間の処理では中断される場合があります。エージェントアシスタントモードではサポートされていません)。Cloudflare のタイムアウトは 100 s です。省略した場合、デフォルトはブロッキング動作になります。
streaming, blocking 会話を継続するための会話 ID です。前のメッセージの conversation_id を渡します。新しい会話を開始するには、このフィールドを省略するか空文字列を渡します。レスポンスで conversation_id が返されます——以降のメッセージでこの値を渡すとその会話を継続できます。
マルチモーダル理解用のファイルリストです。画像、ドキュメント、音声、動画を含みます。ローカルファイルを添付するには、まず ファイルをアップロード でアップロードし、返された id を upload_file_id として transfer_method: local_file で使用します。
Show child attributes
Show child attributes
Response
リクエスト成功。コンテンツタイプと構造はリクエストの response_mode パラメータに依存します。
response_modeがblockingの場合、application/jsonでChatCompletionResponseオブジェクトを返します。response_modeがstreamingの場合、text/event-streamでサーバー送信イベントのストリームを返します。
イベントタイプ。message に固定されています。
リクエスト追跡およびレスポンス停止 API 用のタスク ID です。
このレスポンスイベントの一意 ID です。
一意のメッセージ ID です。フィードバックや推奨質問のエンドポイントを呼び出す際に message_id パラメータとして使用します。
会話 ID。
アプリモード。chat はチャットボットアプリ、agent-chat は Agent アプリです。
完全なレスポンスコンテンツ。
使用量と検索リソースを含むメタデータ。
Show child attributes
Show child attributes
メッセージ作成タイムスタンプ(Unix エポック秒)。
Was this page helpful?
curl --request POST \
--url https://{api_base_url}/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"inputs": {
"city": "San Francisco"
},
"query": "What are the specs of the iPhone 13 Pro Max?",
"response_mode": "streaming",
"conversation_id": "",
"user": "abc-123",
"files": [
{
"type": "image",
"transfer_method": "remote_url",
"url": "https://cloud.dify.ai/logo/logo-site.png"
}
]
}
'{
"event": "message",
"task_id": "c3800678-a077-43df-a102-53f23ed20b88",
"id": "b01a39de-3480-4f3e-9f1e-4841a80f8e5e",
"message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"mode": "chat",
"answer": "iPhone 13 Pro Max specs are listed here:...",
"metadata": {
"usage": {
"prompt_tokens": 1033,
"prompt_unit_price": "0.001",
"prompt_price_unit": "0.001",
"prompt_price": "0.0010330",
"completion_tokens": 128,
"completion_unit_price": "0.002",
"completion_price_unit": "0.001",
"completion_price": "0.0002560",
"total_tokens": 1161,
"total_price": "0.0012890",
"currency": "USD",
"latency": 0.7682376249867957
},
"retriever_resources": [
{
"position": 1,
"dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
"dataset_name": "iPhone",
"document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
"document_name": "iPhone List",
"segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
"score": 0.98457545,
"content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\" \"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
}
]
},
"created_at": 1705407629
}