Skip to main content
POST
/
chat-messages
チャットメッセージを送信
curl --request POST \
  --url http://{api_base_url}/chat-messages \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "inputs": {
    "name": "dify"
  },
  "query": "iPhone 13 Pro Maxの仕様は何ですか?",
  "response_mode": "streaming",
  "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  "user": "abc-123",
  "files": [
    {
      "type": "image",
      "transfer_method": "remote_url",
      "url": "https://cloud.dify.ai/logo/logo-site.png"
    }
  ]
}
'
{
  "event": "message",
  "task_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "message_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "conversation_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "mode": "chat",
  "answer": "<string>",
  "metadata": {
    "usage": {
      "prompt_tokens": 123,
      "prompt_unit_price": "<string>",
      "prompt_price_unit": "<string>",
      "prompt_price": "<string>",
      "completion_tokens": 123,
      "completion_unit_price": "<string>",
      "completion_price_unit": "<string>",
      "completion_price": "<string>",
      "total_tokens": 123,
      "total_price": "<string>",
      "currency": "<string>",
      "latency": 123
    },
    "retriever_resources": [
      {
        "position": 123,
        "dataset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
        "dataset_name": "<string>",
        "document_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
        "document_name": "<string>",
        "segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
        "score": 123,
        "content": "<string>"
      }
    ]
  },
  "created_at": 123
}

Authorizations

Authorization
string
header
required

APIキー認証。すべてのAPIリクエストには、Authorization HTTPヘッダーにAPIキーを Bearer {API_KEY} の形式で含めてください。APIキーはサーバー側に保存し、クライアント側で共有または保存しないことを強くお勧めします。

Body

application/json

チャットメッセージ送信のリクエストボディ。

query
string
required

ユーザー入力/質問内容。

user
string
required

ユーザー識別子。アプリケーション内で一意であるべきです。重要な注意事項: Service API は WebApp で作成された対話を共有しません。API を通じて作成された対話は、WebApp インターフェースで作成されたものとは分離されています。

inputs
object

アプリによって定義されたさまざまな変数値の入力を許可します。変数がファイルタイプの場合、InputFileObjectJp オブジェクトを指定します。

response_mode
enum<string>
default:streaming

応答の返却モード。streaming (推奨) はSSEを使用。blocking は実行完了後に結果を返します (Cloudflareの100秒タイムアウト制限あり)。

Available options:
streaming,
blocking
conversation_id
string<uuid>

会話ID。以前のチャット記録に基づいて会話を続ける場合に必要です。

files
object[]

ファイルリスト。モデルがビジョン機能をサポートしている場合に利用可能です。

auto_generate_name
boolean
default:true

タイトルを自動生成。デフォルトはtrue。

Response

リクエスト成功。応答のコンテントタイプと構造はリクエストの response_mode パラメータに依存します。

  • response_modeblocking の場合、application/json 形式の ChatCompletionResponseJp オブジェクトを返します。
  • response_modestreaming の場合、text/event-stream 形式の ChunkChatflowEventJp オブジェクトのストリームを返します。

ブロッキングモードでの完全なアプリ結果。

event
string

イベントタイプ、固定で message

Example:

"message"

task_id
string<uuid>

タスクID。

id
string<uuid>

ユニークID。

message_id
string<uuid>

一意のメッセージID。

conversation_id
string<uuid>

会話ID。

mode
string

アプリモード、chatとして固定。

Example:

"chat"

answer
string

完全な応答内容。

metadata
object

メタデータ。

created_at
integer

メッセージ作成タイムスタンプ。