> 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
Content-Type: application/json

대화에 입력을 전송하고 에이전트가 완료하거나 클라이언트 도구 결과를 기다릴 때까지 대기합니다. `background`를 true로 설정하면 서버가 턴을 수락할 때 엔드포인트가 202를 반환합니다. 그런 다음 `Last-Event-ID`를 `stream_cursor`로 설정해 턴의 이벤트를 스트리밍하세요. 이 엔드포인트는 알파 단계이며 변경될 수 있습니다.

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

## 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 SendConversationMessageRequestInputItem, required) — 새 턴을 시작하는 `user_message` 하나 또는 대기 중인 턴의 `required_actions`에 응답하고 이를 계속 진행하는 `client_tool_result` 항목을 지정합니다. 제외된 호출은 보류 상태로 유지됩니다. 클라이언트 도구는 시간 제한 없이 대기합니다. 호출이 보류 중인 동안 `user_message`는 거부됩니다. `user_message`에는 `context_id`당 최대 하나의 `contextual_update` 항목을 포함할 수 있습니다. 보류 중인 모든 호출에 응답하는 `client_tool_result` 항목에는 `end` 업데이트를 포함할 수 있습니다.
- `background` (boolean, optional, default: false) — true이면 생성이 완료될 때까지 기다리지 않고 턴이 허용된 후 202 핸들을 반환합니다.

## Response

### 200

성공 응답

- `turn_id` (string, required)
- `status` (enum, required)
  - Allowed values: `in_progress`, `completed`, `requires_action`, `failed`, `timed_out`
- `output` (list of TextOutputItem, optional)
- `error` (AgentOutputError, optional)
- `required_actions` (list of ClientToolCallRequiredAction, optional) — 에이전트가 대기 중인 작업입니다. 계속하려면 각 `client_tool_call`에 대해 `input`의 `client_tool_result` 항목으로 응답하세요.
- `stream_cursor` (string, optional) — 이 턴의 이벤트 스트림을 재개하기 위한 토큰입니다. 턴이 진행 중인 동안 제공되며, 턴의 이벤트를 스트리밍하려면 Last-Event-ID로 전달하세요.

## Errors

### 422 Conversations Send Message Request Unprocessable Entity Error

유효성 검사 오류

- `detail` (list of ValidationError, optional)

## Types

### SendConversationMessageRequestInputItem

- `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개까지 가능합니다.

### TextOutputItem

- `role` ("agent", required)
- `text` (string, required)
- `type` ("text", optional)
- `id` (string, optional)
- `created_at_unix_ms` (integer, 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)

### ValidationError

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

### UserMessageInputItemContentItem

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

### 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입니다.

## Examples

**Request**

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

**Response**

```json
{
  "turn_id": "turn_id",
  "status": "in_progress",
  "output": [
    {
      "role": "agent",
      "text": "text",
      "type": "text",
      "id": "id",
      "created_at_unix_ms": 1
    }
  ],
  "error": {
    "type": "type",
    "code": "code",
    "message": "message"
  },
  "required_actions": [
    {
      "tool_call_id": "tool_call_id",
      "tool_name": "tool_name",
      "parameters": {
        "key": "value"
      },
      "type": "client_tool_call"
    }
  ],
  "stream_cursor": "stream_cursor"
}
```

**SDK Code**

```python
import requests

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

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';
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"

	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")

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")
  .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', [
  '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");
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")! 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()
```