> 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.

# Gửi tin nhắn cho trợ lý

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

Gửi một tin nhắn tới trợ lý AI **mà API key của bạn đang được gán**, và nhận câu trả lời ngay trong response này.

Thiếu scope → `403 INSUFFICIENT_SCOPE`; key mất ràng buộc → `403 ASSISTANT_NOT_BOUND`.

**Bạn không được chọn trợ lý nào trả lời.** `assistantId`, `tenantId`, `apiKeyId`, `model` đều được suy ra từ API key; gửi kèm trong body sẽ bị bỏ qua.

**Cuộc trò chuyện.** Bỏ trống `conversationId` để mở một cuộc trò chuyện mới; response trả về id để dùng cho các tin nhắn tiếp theo.

**Retry và tính phí.** Gửi kèm `Idempotency-Key` — xem mô tả của header này. Nếu không gửi, một lần gửi lại sau lỗi mạng sẽ là lượt chat thứ hai và bị tính phí lần hai.

**File đính kèm.** Tối đa 5 ảnh mỗi tin nhắn qua `files` — dùng `id` từ `POST /agent/files/upload` (`local_file`) hoặc một URL `https` mà OMICX sẽ tự tải (`remote_url`). File tải lên phải thuộc đúng `userId` bạn gửi ở đây, nếu không toàn bộ request nhận `404 FILE_NOT_FOUND` và không lượt nào bị tính phí. Xem `AgentChatFile`.

**Thời gian xử lý.** Một lượt chat thường mất vài giây, có thể lên tới 1 phút — đặt timeout phía client tối thiểu 75 giây. `responseMode: streaming` dành riêng cho biến thể SSE và hiện tại trả về `501`.

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

## Request

### Headers

- `X-Api-Key` (string, required)
- `Idempotency-Key` (string, optional) — Key tự sinh phía client giúp một lượt chat an toàn khi gửi lại. **Rất nên dùng:** không có nó, gửi lại sau lỗi mạng là một lượt chat MỚI và bị tính phí lần nữa — server chỉ tự sinh key nội bộ để bảo vệ retry của chính nó, không giúp được phía bạn. Dùng lại đúng giá trị khi retry. Lượt đã xong được replay lại (`replayed: true`, không tính phí lại); lượt gốc vẫn đang chạy → `409` (`CONVERSATION_BUSY`). Ở tin nhắn đầu tiên, id cuộc trò chuyện được suy ra từ chính key này, nên retry sẽ rơi lại đúng cuộc trò chuyện đã mở thay vì tạo thêm cuộc thứ hai. **Một lượt `FAILED` cũng đã hoàn tất.** `COMPLETED` và `FAILED` đều là trạng thái cuối, replay không phân biệt — một khi đã `FAILED`, mọi lần gọi sau cùng key sẽ nhận lại đúng lỗi đó, trợ lý không được hỏi lại. Vì vậy: - retry vì không thấy phản hồi (timeout, mất kết nối) → **cùng key**; - hỏi lại sau khi đã thấy lượt `FAILED` → **key MỚI**, nếu không sẽ nhận lại đúng lỗi cũ mãi mãi. Dùng key MỚI cho mỗi tin nhắn mới — dùng lại key cũ sẽ trả về câu trả lời cũ mãi mãi.

### Body (application/json)

This endpoint expects an AgentChatRequest.

- `message` (string, required) — Nội dung tin nhắn gửi tới trợ lý.
- `userId` (string, optional) — **Không bắt buộc.** ID CỦA BẠN cho người dùng cuối của bạn — không phải tài khoản OMICX. Truyền vào để gắn cuộc trò chuyện với đúng người dùng cuối đó, nhờ vậy sau này bạn có thể lọc lại theo `userId` khi gọi các API tra cứu (tìm cuộc trò chuyện, lấy thông tin cuộc trò chuyện, đổi tên, đánh giá tin nhắn...). Ổn định theo từng người dùng cuối. **Gửi một định danh KHÔNG MANG NGHĨA — tuyệt đối không dùng email, số điện thoại, số CMND/CCCD hay tên thật.** OMICX coi giá trị này là một chuỗi vô nghĩa: được lưu nguyên văn, dạng plain text, trên mọi cuộc trò chuyện và mọi lượt chat, và xuất hiện trong báo cáo sử dụng. Không có gì ở đây mã hoá, che dấu hay coi nó là dữ liệu cá nhân — một định danh thật ngoài đời đặt vào field này sẽ trở thành dữ liệu cá nhân dạng plain text trong hệ thống của chúng tôi, do chính bạn đặt vào. Một UUID ngẫu nhiên hoặc key người dùng nội bộ của bạn là đúng hình dạng cần có; nếu cần map lại về một người cụ thể, hãy giữ ánh xạ đó ở phía bạn.
- `conversationId` (string, optional) — Tiếp tục một cuộc trò chuyện đã có. Bỏ trống để mở cuộc trò chuyện mới — id của cuộc mới được suy ra từ `Idempotency-Key`, nên gửi lại tin nhắn đầu tiên không tạo thêm cuộc thứ hai. Id để dùng lại được trả về trong response dưới tên `conversationId`.
- `responseMode` (enum, optional, default: blocking) — `blocking` (mặc định) — câu trả lời được trả về ngay trong response này. `streaming` được chấp nhận trong hợp đồng nhưng hiện tại luôn trả `501 STREAMING_NOT_AVAILABLE`; sẽ hoạt động mà không cần bạn đổi gì thêm khi ra mắt.
  - Allowed values: `blocking`, `streaming`
- `inputs` (map from string to any, optional) — Biến của riêng bạn, được chuyển thẳng cho trợ lý nguyên văn. Không bao giờ được lưu lại hay ghi log. Giới hạn (vượt quá → `400 AI_ASSISTANT_INPUTS_INVALID`): là một **object** JSON (không phải array), tối đa **50** key ở cấp cao nhất, lồng sâu tối đa **5** cấp, tối đa **16 KiB** sau khi serialize.
- `files` (list of AgentChatFile, optional) — Ảnh đính kèm cho tin nhắn này, tối đa **5** (nhiều hơn → `400`). Hai cách gửi lên — xem `AgentChatFile`. Bỏ trống nếu không có.

## Response

### 201

Trợ lý đã trả lời.

- `conversationId` (string, optional) — Luồng cuộc trò chuyện này thuộc về — gửi lại để tiếp tục.
- `title` (string, optional) — Tên hiển thị của luồng, tính đến sau lượt chat này.
- `newConversation` (boolean, optional) — `true` khi tin nhắn này mở ra luồng mới.
- `replayed` (boolean, optional) — `true` khi đây là replay của một lượt chat trước với cùng `Idempotency-Key` — không tính phí lại.
- `turn` (AgentChatTurn, optional)

## Errors

### 400 Bad Request Error

Request không hợp lệ. Các subCode: `AI_ASSISTANT_INPUTS_INVALID` — `inputs` không phải object, hoặc vượt giới hạn số key/độ sâu/ kích thước; `VALIDATION_ERROR` — thiếu/quá dài `userId` hoặc `message`, `responseMode` không hợp lệ, hoặc `Idempotency-Key` dài quá 100 ký tự; `AI_ASSISTANT_TURN_INVALID` — lỗi từ hệ thống xử lý AI.

- `error` (ErrorDetail, required)

### 401 Unauthorized Error

Thiếu hoặc sai API key.

- `error` (ErrorDetail, required)

### 403 Forbidden Error

`INSUFFICIENT_SCOPE` — key không có scope `assistant:execute`; `ASSISTANT_NOT_BOUND` — key có scope nhưng không (còn) được gán trợ lý.

- `error` (ErrorDetail, required)

### 404 Not Found Error

Trợ lý được gán không còn tồn tại (`AI_ASSISTANT_NOT_FOUND`).

- `error` (ErrorDetail, required)

### 409 Conflict Error

`CONVERSATION_BUSY` — một lượt chat với cùng `Idempotency-Key` vẫn đang chạy, hãy chờ thay vì gửi lại; `AI_ASSISTANT_DISABLED` — trợ lý đã bị chủ sở hữu tắt.

- `error` (ErrorDetail, required)

### 429 Too Many Requests Error

`RATE_LIMIT_EXCEEDED`.

- `error` (ErrorDetail, required)

### 501 Not Implemented Error

`STREAMING_NOT_AVAILABLE` — `responseMode: streaming` chưa khả dụng. Dùng `blocking`; khi streaming ra mắt sẽ không cần đổi gì thêm phía bạn.

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

### 503 Service Unavailable Error

`SERVICE_OVERLOADED` — quá nhiều request chat đồng thời trên node này. Thử lại sau 5 giây.

- `error` (ErrorDetail, required)

## Types

### AgentChatFile

Một ảnh đính kèm. **`local_file` — bạn đã tải lên cho OMICX trước.** Gửi `id` từ `POST /agent/files/upload` dưới tên `uploadFileId`. File đó phải được tải lên bởi CÙNG `userId` bạn gửi ở tin nhắn này; khác đi sẽ nhận `404 FILE_NOT_FOUND`, tương tự với một id không tồn tại hoặc đã bị xoá. Đây là cách được khuyến nghị — dữ liệu đó đã được kiểm tra loại và giới hạn dung lượng khi lưu. **`remote_url` — OMICX tự tải về từ chỗ bạn.** Gửi một URL `https` mà OMICX có thể truy cập được. OMICX KHÔNG sao chép lại ảnh; nếu URL sau đó hết hạn hoặc bạn xoá đi, ảnh đính kèm sẽ không còn hiển thị được trong lịch sử. Loại, dung lượng và nội dung của ảnh hoàn toàn không được OMICX kiểm tra — chỉ nằm giữa URL đó và trợ lý. `objectKey` không được chấp nhận; file chỉ được tham chiếu qua id không mang nghĩa mà OMICX đã trả về.

- `type` (enum, required) — Chỉ hỗ trợ ảnh.
  - Allowed values: `image`
- `transferMethod` (enum, required)
  - Allowed values: `local_file`, `remote_url`
- `uploadFileId` (string, optional) — Bắt buộc khi `transferMethod` là `local_file`, và phải bỏ trống trong trường hợp khác. Là `id` từ `POST /agent/files/upload`.
- `url` (string, optional) — Bắt buộc khi `transferMethod` là `remote_url`, và phải bỏ trống trong trường hợp khác. Phải là `https` (`http` thường → `400`), không được nhúng thông tin đăng nhập (`https://user:pass@host/...` → `400`), và không được trỏ vào địa chỉ private/loopback/link-local (`127.0.0.0/8`, `10/8`, `172.16/12`, `192.168/16`, `169.254/16`, `::1`, `fc00::/7`, `localhost`, `*.local`, `*.internal` → `400`).

### 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

### Tin nhắn văn bản

**Request**

```json
{
  "message": "Cho tôi biết trạng thái đơn hàng ORD-123",
  "userId": "partner-user-42",
  "inputs": {
    "orderId": "ORD-123"
  }
}
```

**Response**

```json
{
  "conversationId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a",
  "title": "Trạng thái đơn hàng",
  "newConversation": true,
  "replayed": false,
  "turn": {
    "id": "018f8b40-1111-7a2c-8e4f-5b6c7d8e9f0a",
    "status": "COMPLETED",
    "messages": [
      {
        "role": "USER",
        "content": "Cho tôi biết trạng thái đơn hàng ORD-123",
        "createdAt": 1767225600000
      },
      {
        "role": "ASSISTANT",
        "content": "Đơn ORD-123 đang được giao, dự kiến đến ngày 03/01.",
        "createdAt": 1767225604120
      }
    ],
    "model": {
      "provider": "openai",
      "modelId": "gpt-4o-mini"
    },
    "usage": {
      "inputTokens": 412,
      "outputTokens": 96,
      "totalTokens": 508
    },
    "creditUsed": 51,
    "durationMs": 4120,
    "contentTruncated": false,
    "skillsApiUsed": [
      "018f8b12-aaaa-7a2c-8e4f-5b6c7d8e9f0a"
    ],
    "skillsSystemUsed": [],
    "documentsUsed": [],
    "skillsUsed": [
      {
        "id": "018f8b12-aaaa-7a2c-8e4f-5b6c7d8e9f0a",
        "callId": "call_01",
        "type": "API"
      }
    ]
  }
}
```

**SDK Code**

```python Tin nhắn văn bản
import requests

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

payload = {
    "message": "Cho tôi biết trạng thái đơn hàng ORD-123",
    "userId": "partner-user-42",
    "inputs": { "orderId": "ORD-123" }
}
headers = {
    "X-Api-Key": "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Tin nhắn văn bản
const url = 'https://api.omicx.one/agent/chat-messages';
const options = {
  method: 'POST',
  headers: {
    'X-Api-Key': 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Content-Type': 'application/json'
  },
  body: '{"message":"Cho tôi biết trạng thái đơn hàng ORD-123","userId":"partner-user-42","inputs":{"orderId":"ORD-123"}}'
};

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

```go Tin nhắn văn bản
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"message\": \"Cho tôi biết trạng thái đơn hàng ORD-123\",\n  \"userId\": \"partner-user-42\",\n  \"inputs\": {\n    \"orderId\": \"ORD-123\"\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 Tin nhắn văn bản
require 'uri'
require 'net/http'

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

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  \"message\": \"Cho tôi biết trạng thái đơn hàng ORD-123\",\n  \"userId\": \"partner-user-42\",\n  \"inputs\": {\n    \"orderId\": \"ORD-123\"\n  }\n}"

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

```java Tin nhắn văn bản
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.omicx.one/agent/chat-messages")
  .header("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  .header("Content-Type", "application/json")
  .body("{\n  \"message\": \"Cho tôi biết trạng thái đơn hàng ORD-123\",\n  \"userId\": \"partner-user-42\",\n  \"inputs\": {\n    \"orderId\": \"ORD-123\"\n  }\n}")
  .asString();
```

```php Tin nhắn văn bản
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.omicx.one/agent/chat-messages', [
  'body' => '{
  "message": "Cho tôi biết trạng thái đơn hàng ORD-123",
  "userId": "partner-user-42",
  "inputs": {
    "orderId": "ORD-123"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Api-Key' => 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  ],
]);

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

```csharp Tin nhắn văn bản
using RestSharp;

var client = new RestClient("https://api.omicx.one/agent/chat-messages");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"message\": \"Cho tôi biết trạng thái đơn hàng ORD-123\",\n  \"userId\": \"partner-user-42\",\n  \"inputs\": {\n    \"orderId\": \"ORD-123\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Tin nhắn văn bản
import Foundation

let headers = [
  "X-Api-Key": "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "Content-Type": "application/json"
]
let parameters = [
  "message": "Cho tôi biết trạng thái đơn hàng ORD-123",
  "userId": "partner-user-42",
  "inputs": ["orderId": "ORD-123"]
] as [String : Any]

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

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

### Gửi kèm ảnh đính kèm

**Request**

```json
{
  "message": "Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng",
  "userId": "partner-user-42",
  "files": [
    {
      "type": "image",
      "transferMethod": "local_file",
      "uploadFileId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a"
    },
    {
      "type": "image",
      "transferMethod": "remote_url",
      "url": "https://cdn.partner.example/orders/ORD-123.png"
    }
  ]
}
```

**Response**

```json
{
  "conversationId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a",
  "title": "Trạng thái đơn hàng",
  "newConversation": true,
  "replayed": false,
  "turn": {
    "id": "018f8b40-1111-7a2c-8e4f-5b6c7d8e9f0a",
    "status": "COMPLETED",
    "messages": [
      {
        "role": "USER",
        "content": "Cho tôi biết trạng thái đơn hàng ORD-123",
        "createdAt": 1767225600000
      },
      {
        "role": "ASSISTANT",
        "content": "Đơn ORD-123 đang được giao, dự kiến đến ngày 03/01.",
        "createdAt": 1767225604120
      }
    ],
    "model": {
      "provider": "openai",
      "modelId": "gpt-4o-mini"
    },
    "usage": {
      "inputTokens": 412,
      "outputTokens": 96,
      "totalTokens": 508
    },
    "creditUsed": 51,
    "durationMs": 4120,
    "contentTruncated": false,
    "skillsApiUsed": [
      "018f8b12-aaaa-7a2c-8e4f-5b6c7d8e9f0a"
    ],
    "skillsSystemUsed": [],
    "documentsUsed": [],
    "skillsUsed": [
      {
        "id": "018f8b12-aaaa-7a2c-8e4f-5b6c7d8e9f0a",
        "callId": "call_01",
        "type": "API"
      }
    ]
  }
}
```

**SDK Code**

```python Gửi kèm ảnh đính kèm
import requests

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

payload = {
    "message": "Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng",
    "userId": "partner-user-42",
    "files": [
        {
            "type": "image",
            "transferMethod": "local_file",
            "uploadFileId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a"
        },
        {
            "type": "image",
            "transferMethod": "remote_url",
            "url": "https://cdn.partner.example/orders/ORD-123.png"
        }
    ]
}
headers = {
    "X-Api-Key": "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Gửi kèm ảnh đính kèm
const url = 'https://api.omicx.one/agent/chat-messages';
const options = {
  method: 'POST',
  headers: {
    'X-Api-Key': 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Content-Type': 'application/json'
  },
  body: '{"message":"Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng","userId":"partner-user-42","files":[{"type":"image","transferMethod":"local_file","uploadFileId":"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a"},{"type":"image","transferMethod":"remote_url","url":"https://cdn.partner.example/orders/ORD-123.png"}]}'
};

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

```go Gửi kèm ảnh đính kèm
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"message\": \"Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng\",\n  \"userId\": \"partner-user-42\",\n  \"files\": [\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"local_file\",\n      \"uploadFileId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\"\n    },\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"remote_url\",\n      \"url\": \"https://cdn.partner.example/orders/ORD-123.png\"\n    }\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 Gửi kèm ảnh đính kèm
require 'uri'
require 'net/http'

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

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  \"message\": \"Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng\",\n  \"userId\": \"partner-user-42\",\n  \"files\": [\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"local_file\",\n      \"uploadFileId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\"\n    },\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"remote_url\",\n      \"url\": \"https://cdn.partner.example/orders/ORD-123.png\"\n    }\n  ]\n}"

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

```java Gửi kèm ảnh đính kèm
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.omicx.one/agent/chat-messages")
  .header("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  .header("Content-Type", "application/json")
  .body("{\n  \"message\": \"Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng\",\n  \"userId\": \"partner-user-42\",\n  \"files\": [\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"local_file\",\n      \"uploadFileId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\"\n    },\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"remote_url\",\n      \"url\": \"https://cdn.partner.example/orders/ORD-123.png\"\n    }\n  ]\n}")
  .asString();
```

```php Gửi kèm ảnh đính kèm
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.omicx.one/agent/chat-messages', [
  'body' => '{
  "message": "Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng",
  "userId": "partner-user-42",
  "files": [
    {
      "type": "image",
      "transferMethod": "local_file",
      "uploadFileId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a"
    },
    {
      "type": "image",
      "transferMethod": "remote_url",
      "url": "https://cdn.partner.example/orders/ORD-123.png"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Api-Key' => 'omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  ],
]);

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

```csharp Gửi kèm ảnh đính kèm
using RestSharp;

var client = new RestClient("https://api.omicx.one/agent/chat-messages");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Api-Key", "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"message\": \"Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng\",\n  \"userId\": \"partner-user-42\",\n  \"files\": [\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"local_file\",\n      \"uploadFileId\": \"018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a\"\n    },\n    {\n      \"type\": \"image\",\n      \"transferMethod\": \"remote_url\",\n      \"url\": \"https://cdn.partner.example/orders/ORD-123.png\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Gửi kèm ảnh đính kèm
import Foundation

let headers = [
  "X-Api-Key": "omx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "Content-Type": "application/json"
]
let parameters = [
  "message": "Đây là ảnh chụp hoá đơn, kiểm tra giúp tôi thông tin đơn hàng",
  "userId": "partner-user-42",
  "files": [
    [
      "type": "image",
      "transferMethod": "local_file",
      "uploadFileId": "018f8b3c-6d1b-7a2c-8e4f-5b6c7d8e9f0a"
    ],
    [
      "type": "image",
      "transferMethod": "remote_url",
      "url": "https://cdn.partner.example/orders/ORD-123.png"
    ]
  ]
] as [String : Any]

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

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