> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.omicx.one/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.omicx.one/_mcp/server.

# Tìm tin nhắn trong cuộc trò chuyện

POST https://api.omicx.one/agent/chat-messages/search
Content-Type: application/json

Thứ tự cố định là lượt mới nhất trước — client tự đảo ngược từng trang khi hiển thị theo thứ tự cũ nhất trước.

Reference: https://developers.omicx.one/agent/chat/search-agent-chat-messages

## Request

### Headers

- `X-Api-Key` (string, required)

### Body (application/json)

This endpoint expects an AgentTurnSearchRequest.

- `filter` (AgentTurnSearchRequestFilter, required)
- `pagination` (AgentPagination, optional)

## Response

### 200

Lịch sử tin nhắn có phân trang.

- `items` (list of AgentChatTurn, required)
- `page` (integer, required)
- `size` (integer, required)
- `totalItems` (long, required)
- `totalPages` (integer, required)

## Errors

### 400 Bad Request Error

Thiếu hoặc sai `userId`/`conversationId`/thông tin phân trang.

- `error` (ErrorDetail, required)

### 401 Unauthorized Error

Thiếu hoặc sai API key.

- `error` (ErrorDetail, required)

### 403 Forbidden Error

Thiếu scope `assistant:execute`, hoặc key không còn được gán trợ lý.

- `error` (ErrorDetail, required)

### 404 Not Found Error

Không tìm thấy cuộc trò chuyện trong phạm vi tenant/trợ lý/key/user này.

- `error` (ErrorDetail, required)

### 502 Bad Gateway Error

Hệ thống xử lý AI tạm thời không khả dụng.

- `error` (ErrorDetail, required)

## Types

### AgentTurnSearchRequestFilter

- `conversationId` (string, required)
- `userId` (string, optional) — Không bắt buộc — cùng định danh không mang nghĩa bạn dùng để chat (xem `AgentChatRequest.userId`). Truyền vào để lọc/tra cứu theo đúng người dùng cuối đó.

### AgentPagination

- `page` (integer, optional, default: 1)
- `size` (integer, optional, default: 20)

### AgentChatTurn

- `id` (string, optional)
- `status` (enum, optional) — Trạng thái cuối là `COMPLETED` và `FAILED`. Một lượt gọi blocking luôn trả về trạng thái cuối.
  - Allowed values: `RUNNING`, `COMPLETED`, `FAILED`
- `messages` (list of AgentChatTurnMessagesItems, optional) — Tin nhắn của người dùng, và câu trả lời của trợ lý nếu có (lượt `FAILED` chỉ có tin nhắn của người dùng).
- `files` (list of AgentTurnFile, optional) — Ảnh đã đính kèm vào tin nhắn của người dùng; rỗng nếu không có. Mỗi `url` được cấp mới cho response này và sẽ hết hạn — không lưu lại.
- `model` (AgentChatTurnModel, optional)
- `usage` (AgentChatTurnUsage, optional)
- `creditUsed` (long, optional) — Chi phí đã tính của lượt chat này. Lượt `FAILED` luôn là 0.
- `durationMs` (long, optional, nullable)
- `contentTruncated` (boolean, optional) — `true` khi câu trả lời dài hơn giới hạn lưu trữ và đã bị cắt.
- `skillsApiUsed` (list of string, optional) — Id các kỹ năng API mà lượt chat này đã dùng.
- `skillsSystemUsed` (list of string, optional) — Tên các kỹ năng có sẵn, ví dụ `web_search`.
- `documentsUsed` (list of string, optional) — Id các tài liệu tri thức mà lượt chat này đã dùng.
- `skillsUsed` (list of AgentChatTurnSkillsUsedItems, optional) — Một dòng CHO MỖI LẦN GỌI — một kỹ năng được gọi 2 lần sẽ xuất hiện 2 dòng.
- `errorCode` (string, optional, nullable) — Có giá trị khi lượt chat `FAILED`.
- `feedback` (enum, optional, nullable) — Đánh giá đã ghi nhận cho câu trả lời này, nếu có.
  - Allowed values: `LIKE`, `DISLIKE`

### ErrorDetail

- `code` (string, required) — Nhóm lỗi (dạng máy đọc được), ổn định theo từng HTTP status.
- `message` (string, required) — Mô tả cho con người đọc (dùng để debug), không nên dịch trực tiếp.
- `timestamp` (datetime, required)
- `path` (string, required) — Đường dẫn request đầy đủ.
- `subCode` (string, optional, nullable) — Mã cụ thể, ổn định — dùng để phân nhánh xử lý / dịch i18n. Hãy xử lý logic dựa trên `subCode`, không dựa vào chuỗi `message`.
- `details` (list of ErrorDetailDetailsItems, optional, nullable) — Lỗi theo từng field (chỉ có khi `code` là `VALIDATION_ERROR`).

### AgentChatTurnMessagesItems

- `role` (enum, optional)
  - Allowed values: `USER`, `ASSISTANT`
- `content` (string, optional)
- `createdAt` (long, optional) — Epoch millis.

### AgentTurnFile

Một ảnh đã được đính kèm cho tin nhắn này, khi đọc lại. `url` là link **sống ngắn hạn**, được cấp mới mỗi lần bạn đọc lại transcript — không lưu lại giá trị này. Trả về `null` khi ảnh không còn phục vụ được: file đã upload bị xoá, hoặc là `remote_url` được trả về đúng như bạn gửi lên và có thể đã hết hạn.

- `type` (enum, optional)
  - Allowed values: `image`
- `url` (string, optional, nullable) — Link tải sống ngắn hạn, hoặc `null` khi ảnh không còn khả dụng.
- `mimeType` (string, optional, nullable) — Nhận diện từ nội dung file lúc upload. `null` với `remote_url` — OMICX không bao giờ đọc bytes của loại này.
- `name` (string, optional, nullable)

### AgentChatTurnModel

- `provider` (string, optional)
- `modelId` (string, optional)

### AgentChatTurnUsage

- `inputTokens` (long, optional)
- `outputTokens` (long, optional)
- `totalTokens` (long, optional)

### AgentChatTurnSkillsUsedItems

- `id` (string, optional)
- `callId` (string, optional)
- `type` (enum, optional)
  - Allowed values: `SYSTEM`, `API`

### ErrorDetailDetailsItems

- `field` (string, optional)
- `message` (string, optional)
- `rejectedValue` (any, optional, nullable)

## Examples

**Request**

```json
{
  "filter": {
    "conversationId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a",
    "userId": "partner-user-42"
  },
  "pagination": {
    "page": 1,
    "size": 20
  }
}
```

**Response**

```json
{
  "items": [
    {
      "id": "018f8b40-1111-7a2c-8e4f-5b6c7d8e9f0a",
      "status": "RUNNING",
      "messages": [
        {
          "role": "USER",
          "content": "string",
          "createdAt": 1
        }
      ],
      "files": [
        {
          "type": "image",
          "url": "https://minio.example/omicx-files/permanent/...?X-Amz-Signature=...",
          "mimeType": "image/png",
          "name": "don-hang.png"
        }
      ],
      "model": {
        "provider": "openai",
        "modelId": "gpt-4o-mini"
      },
      "usage": {
        "inputTokens": 1,
        "outputTokens": 1,
        "totalTokens": 1
      },
      "creditUsed": 1,
      "durationMs": 1,
      "contentTruncated": true,
      "skillsApiUsed": [
        "string"
      ],
      "skillsSystemUsed": [
        "string"
      ],
      "documentsUsed": [
        "string"
      ],
      "skillsUsed": [
        {
          "id": "string",
          "callId": "string",
          "type": "SYSTEM"
        }
      ],
      "errorCode": "string",
      "feedback": "LIKE"
    }
  ],
  "page": 1,
  "size": 1,
  "totalItems": 1,
  "totalPages": 1
}
```

**SDK Code**

```python default
import requests

url = "https://api.omicx.one/agent/chat-messages/search"

payload = {
    "filter": {
        "conversationId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a",
        "userId": "partner-user-42"
    },
    "pagination": {
        "page": 1,
        "size": 20
    }
}
headers = {
    "X-Api-Key": "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript default
const url = 'https://api.omicx.one/agent/chat-messages/search';
const options = {
  method: 'POST',
  headers: {
    'X-Api-Key': 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Content-Type': 'application/json'
  },
  body: '{"filter":{"conversationId":"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a","userId":"partner-user-42"},"pagination":{"page":1,"size":20}}'
};

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

```go default
package main

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

func main() {

	url := "https://api.omicx.one/agent/chat-messages/search"

	payload := strings.NewReader("{\n  \"filter\": {\n    \"conversationId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\",\n    \"userId\": \"partner-user-42\"\n  },\n  \"pagination\": {\n    \"page\": 1,\n    \"size\": 20\n  }\n}")

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

	req.Header.Add("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
	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 default
require 'uri'
require 'net/http'

url = URI("https://api.omicx.one/agent/chat-messages/search")

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

request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"filter\": {\n    \"conversationId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\",\n    \"userId\": \"partner-user-42\"\n  },\n  \"pagination\": {\n    \"page\": 1,\n    \"size\": 20\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.omicx.one/agent/chat-messages/search")
  .header("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  .header("Content-Type", "application/json")
  .body("{\n  \"filter\": {\n    \"conversationId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\",\n    \"userId\": \"partner-user-42\"\n  },\n  \"pagination\": {\n    \"page\": 1,\n    \"size\": 20\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.omicx.one/agent/chat-messages/search', [
  'body' => '{
  "filter": {
    "conversationId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a",
    "userId": "partner-user-42"
  },
  "pagination": {
    "page": 1,
    "size": 20
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Api-Key' => 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  ],
]);

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

```csharp default
using RestSharp;

var client = new RestClient("https://api.omicx.one/agent/chat-messages/search");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"filter\": {\n    \"conversationId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\",\n    \"userId\": \"partner-user-42\"\n  },\n  \"pagination\": {\n    \"page\": 1,\n    \"size\": 20\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift default
import Foundation

let headers = [
  "X-Api-Key": "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "Content-Type": "application/json"
]
let parameters = [
  "filter": [
    "conversationId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a",
    "userId": "partner-user-42"
  ],
  "pagination": [
    "page": 1,
    "size": 20
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.omicx.one/agent/chat-messages/search")! 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()
```