> This is a page from the ElevenLabs documentation. For an index of the documentation, fetch https://elevenlabs.io/docs/llms.txt.

# 대화 메시지 스트림 전송

POST https://api.elevenlabs.io/v1/convai/conversations/{conversation_id}/messages/stream
Content-Type: application/json

대화에 입력을 전송하고 요청의 이벤트를 서버 전송 이벤트로 스트리밍합니다. 마지막 이벤트는 턴의 결과를 포함하는 `stream_ended`입니다. 이 엔드포인트는 알파 단계이며 변경될 수 있습니다.

Reference: https://elevenlabs.io/docs/eleven-agents/api-reference/conversations/send-message-stream

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Path parameters

- `conversation_id` (string, required) — 대화 ID

### Body (application/json)

This endpoint expects an object.

- `input` (list of SendConversationMessageStreamRequestInputItem, required) — 새 턴을 시작하는 `user_message` 하나 또는 대기 중인 턴의 `required_actions`에 응답하고 이를 계속 진행하는 `client_tool_result` 항목을 지정합니다. 제외된 호출은 보류 상태로 유지됩니다. 클라이언트 도구는 시간 제한 없이 대기합니다. 호출이 보류 중인 동안 `user_message`는 거부됩니다. `user_message`에는 `context_id`당 최대 하나의 `contextual_update` 항목을 포함할 수 있습니다. 보류 중인 모든 호출에 응답하는 `client_tool_result` 항목에는 `end` 업데이트를 포함할 수 있습니다.

## Response

### 200

서버 전송 이벤트입니다. 각 이벤트에는 스트림 커서가 `id`로, 이벤트 유형이 `event`로, 스트림 엔벨로프가 `data`로 포함됩니다.

- Streaming response of `StreamEnvelope`.
- `conversation_id` (string, required)
- `turn_id` (string, required)
- `created_at_unix_ms` (integer, required)
- `event` (StreamEnvelopeEvent, required)

## Errors

### 422 Conversations Send Message Stream Request Unprocessable Entity Error

유효성 검사 오류

- `detail` (list of ValidationError, optional)

## Types

### SendConversationMessageStreamRequestInputItem

- `type`: `client_tool_result`
  - `is_error` (boolean, required)
  - `result` (string, required)
  - `tool_call_id` (string, required) — 이 결과에 해당하는 도구 호출의 ID입니다.
  - `error_type` (enum, optional) — 실패 이유의 선택적 카테고리입니다. 설정하면 `is_error`는 true로 처리됩니다. `user_rejected`는 도구가 호출되지 않은 것으로 표시하도록 특별 처리됩니다.
    - Allowed values: `user_rejected`, `external_server`, `external_client`, `customer_auth`, `client_timeout`, `unknown`
- `type`: `contextual_update`
  - `context_id` (string, required) — 업데이트가 설명하는 내용입니다. 에이전트는 각 `context_id`에 대한 최신 업데이트만 확인합니다.
  - `text` (string, required) — Context for the agent that the user did not write, such as the client's current state.
  - `placement` (enum, optional, default: in_place) — `in_place`: the update stays where it was sent, like an event. `end`: the update is current state, sent after the newest message or tool result.
    - Allowed values: `in_place`, `end`
- `type`: `user_message`
  - `content` (list of UserMessageInputItemContentItem, required) — 메시지의 구성 요소입니다. 텍스트 구성 요소는 최대 1개, 파일 구성 요소는 최대 5개까지 가능합니다.

### StreamEnvelopeEvent

- `type`: `agent_chat_response_part`
  - `text_response_part` (AgentChatResponsePartClientEventData, required)
- `type`: `agent_reasoning_response_part`
  - `reasoning_response_part` (AgentReasoningResponsePartClientEventData, required)
- `type`: `agent_response`
  - `agent_response_event` (AgentResponseClientEventData, required)
- `type`: `agent_tool_request`
  - `agent_tool_request` (AgentToolRequestClientEventData, required)
- `type`: `agent_tool_response`
  - `agent_tool_response` (AgentToolResponseClientEventData, required)
- `type`: `client_tool_call`
  - `client_tool_call` (ClientToolCallClientEventData, required)
- `type`: `stream_ended`
  - `stream_ended_event` (StreamEndedData, required)

### ValidationError

- `loc` (list of ValidationErrorLocItem, required)
- `msg` (string, required)
- `type` (string, required)

### UserMessageInputItemContentItem

- `type`: `file`
  - `source` (FileContentPartSource, required)
- `type`: `text`
  - `text` (string, required)

### AgentChatResponsePartClientEventData

- `text` (string, required)
- `type` (enum, required)
  - Allowed values: `start`, `delta`, `stop`
- `event_id` (integer, required)
- `response_id` (string, required)

### AgentReasoningResponsePartClientEventData

- `text` (string, required)
- `type` (enum, required)
  - Allowed values: `start`, `delta`, `stop`
- `event_id` (integer, required)

### AgentResponseClientEventData

- `agent_response` (string, required)
- `event_id` (integer, required)
- `response_id` (string, required)
- `in_response_to_ids` (list of string, optional)
- `response_type` (enum, optional, default: text)
  - Allowed values: `text`, `voice`
- `attachments` (list of AgentResponseAttachment, optional)

### AgentToolRequestClientEventData

- `tool_name` (string, required)
- `tool_call_id` (string, required)
- `tool_type` (string, required)
- `event_id` (integer, required)
- `expects_response` (boolean, required)
- `disable_interruptions` (boolean, required)
- `response_timeout_secs` (integer, required)
- `execution_mode` (string, required)

### AgentToolResponseClientEventData

- `tool_name` (string, required)
- `tool_call_id` (string, required)
- `tool_type` (string, required)
- `is_error` (boolean, required)
- `event_id` (integer, required)
- `is_called` (boolean, required)
- `is_blocked` (boolean, optional, default: false)
- `status` (enum, optional) — 실행 플래그에서 파생된 도구 호출 상태입니다.
  - Allowed values: `success`, `error`, `blocked`, `skipped`

### ClientToolCallClientEventData

- `tool_name` (string, required)
- `tool_call_id` (string, required)
- `parameters` (map from string to any, required)
- `event_id` (integer, required)
- `expects_response` (boolean, required) — 서버가 ClientToolResult 응답을 예상하는지 여부입니다.

### StreamEndedData

- `status` (enum, required)
  - Allowed values: `in_progress`, `completed`, `requires_action`, `failed`, `timed_out`
- `error` (AgentOutputError, optional)
- `required_actions` (list of ClientToolCallRequiredAction, optional) — 에이전트가 대기 중인 작업입니다. 계속하려면 각 `client_tool_call`에 대해 `input`의 `client_tool_result` 항목으로 응답하세요.

### ValidationErrorLocItem

- string
- integer

### FileContentPartSource

- `type`: `base64`
  - `data` (string, required) — base64로 인코딩된 파일 콘텐츠입니다.
  - `filename` (string, required) — 확장자를 포함한 파일 이름입니다.
  - `media_type` (enum, required)
    - Allowed values: `image/png`, `image/jpeg`, `image/gif`, `image/webp`, `application/pdf`, `text/plain`
- `type`: `file_id`
  - `file_id` (string, required) — 이 대화에 대해 `POST /v1/convai/conversations/{conversation_id}/files`가 반환한 ID입니다.

### AgentResponseAttachment

- `url` (string, required)
- `name` (string, required)
- `mime_type` (string, optional)

### AgentOutputError

- `type` (string, required)
- `code` (string, required)
- `message` (string, required)

### ClientToolCallRequiredAction

- `tool_call_id` (string, required)
- `tool_name` (string, required)
- `parameters` (map from string to any, required)
- `type` ("client_tool_call", optional)

## Examples

**Request**

```json
{
  "input": [
    {
      "type": "client_tool_result",
      "is_error": true,
      "result": "result",
      "tool_call_id": "tool_call_id"
    }
  ]
}
```

**Response**

```text
event: 
data: {"conversation_id":"conversation_id","created_at_unix_ms":1,"event":{"text_response_part":{"event_id":1,"response_id":"response_id","text":"text","type":"start"},"type":"agent_chat_response_part"},"turn_id":"turn_id"}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream"

payload = { "input": [
        {
            "type": "client_tool_result",
            "is_error": True,
            "result": "result",
            "tool_call_id": "tool_call_id"
        }
    ] }
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"input":[{"type":"client_tool_result","is_error":true,"result":"result","tool_call_id":"tool_call_id"}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream"

	payload := strings.NewReader("{\n  \"input\": [\n    {\n      \"type\": \"client_tool_result\",\n      \"is_error\": true,\n      \"result\": \"result\",\n      \"tool_call_id\": \"tool_call_id\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"input\": [\n    {\n      \"type\": \"client_tool_result\",\n      \"is_error\": true,\n      \"result\": \"result\",\n      \"tool_call_id\": \"tool_call_id\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream")
  .header("Content-Type", "application/json")
  .body("{\n  \"input\": [\n    {\n      \"type\": \"client_tool_result\",\n      \"is_error\": true,\n      \"result\": \"result\",\n      \"tool_call_id\": \"tool_call_id\"\n    }\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream', [
  'body' => '{
  "input": [
    {
      "type": "client_tool_result",
      "is_error": true,
      "result": "result",
      "tool_call_id": "tool_call_id"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"input\": [\n    {\n      \"type\": \"client_tool_result\",\n      \"is_error\": true,\n      \"result\": \"result\",\n      \"tool_call_id\": \"tool_call_id\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = ["input": [
    [
      "type": "client_tool_result",
      "is_error": true,
      "result": "result",
      "tool_call_id": "tool_call_id"
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/convai/conversations/conversation_id/messages/stream")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```