AI · API Reference
API — AI
Tài liệu các endpoint của module ai. Mỗi endpoint có request format, response format, lỗi có thể xảy ra và ví dụ thực tế.
Tóm tắt endpoint
| Method | Path | Mô tả | Auth | Rate limit |
|---|
| POST | /api/v1/ai/moderate | Moderate content. [CẦN XÁC NHẬN] stub. | Bearer | Global apiLimiter; một số flow có Redis/domain limit riêng. |
| POST | /api/v1/ai/caption | Generate caption. [CẦN XÁC NHẬN] stub. | Bearer | Global apiLimiter; một số flow có Redis/domain limit riêng. |
| POST | /api/v1/ai/smart-reply | Generate smart reply. [CẦN XÁC NHẬN] stub. | Bearer | Global apiLimiter; một số flow có Redis/domain limit riêng. |
| GET | /api/v1/ai/recommendations | Recommendations. [CẦN XÁC NHẬN] stub. | Bearer | Global apiLimiter; một số flow có Redis/domain limit riêng. |
POST /api/v1/ai/moderate
POST Auth required apiLimiter
Endpoint này dùng để moderate content. [CẦN XÁC NHẬN] stub. Gọi endpoint này khi client cần thao tác đúng phạm vi module ai.
Request
| Header | Giá trị | Bắt buộc | Mô tả |
|---|
| Authorization | Bearer accessToken | Có | JWT access token nếu route protected |
| x-refresh-token | raw refresh token | Không | Refresh token header theo middleware |
| Parameter | Kiểu | Mô tả | Ví dụ |
|---|
| path params | string | Các phần :publicId, :username, :code nếu path có | cm123 |
| query params | string/number | take, after, page, limit hoặc module-specific query | take=20 |
| Field | Kiểu | Bắt buộc | Validation | Mô tả | Ví dụ giá trị |
|---|
| body | object | Tùy endpoint | Theo DTO Zod nếu route có validate() | Payload nghiệp vụ của endpoint | {"content":"Hello"} |
Ví dụ request
curl -X POST http://localhost:3302/api/v1/ai/moderate \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json"
Response
200/201 — Thành công
| Field | Kiểu | Luôn có? | Mô tả |
|---|
| success | boolean | Có | true khi request thành công |
| message | string | Không | Một số controller truyền message |
| data | object/array | Tùy endpoint | Dữ liệu trả về từ service |
| pagination | object | Với list | Cursor/offset pagination |
{
"success": true,
"data": {
"module": "ai",
"endpoint": "/api/v1/ai/moderate"
}
}
Lỗi có thể xảy ra
| HTTP Status | Error Code | Khi nào xảy ra | Cách xử lý ở client |
|---|
| 401 | UNAUTHORIZED | Unauthorized | Login lại hoặc refresh token. |
| 400 | VALIDATION_FAILED | Validation failed | Client sửa field sai. |
| 404 | NOT_FOUND | Resource not found | Refresh dữ liệu. |
| 403 | FORBIDDEN | Forbidden | Ẩn action trong UI. |
| 500 | INTERNAL_SERVER_ERROR | External dependency fail | On-call kiểm tra provider/log. |
Ví dụ lỗi
{
"success": false,
"message": "Validation failed"
}
Ghi chú
- Endpoint đi qua global
apiLimiter. - Idempotency không được đảm bảo trừ khi service có upsert/unique constraint riêng.
- Public AI endpoints là stubs.
POST /api/v1/ai/caption
POST Auth required apiLimiter
Endpoint này dùng để generate caption. [CẦN XÁC NHẬN] stub. Gọi endpoint này khi client cần thao tác đúng phạm vi module ai.
Request
| Header | Giá trị | Bắt buộc | Mô tả |
|---|
| Authorization | Bearer accessToken | Có | JWT access token nếu route protected |
| x-refresh-token | raw refresh token | Không | Refresh token header theo middleware |
| Parameter | Kiểu | Mô tả | Ví dụ |
|---|
| path params | string | Các phần :publicId, :username, :code nếu path có | cm123 |
| query params | string/number | take, after, page, limit hoặc module-specific query | take=20 |
| Field | Kiểu | Bắt buộc | Validation | Mô tả | Ví dụ giá trị |
|---|
| body | object | Tùy endpoint | Theo DTO Zod nếu route có validate() | Payload nghiệp vụ của endpoint | {"content":"Hello"} |
Ví dụ request
curl -X POST http://localhost:3302/api/v1/ai/caption \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json"
Response
200/201 — Thành công
| Field | Kiểu | Luôn có? | Mô tả |
|---|
| success | boolean | Có | true khi request thành công |
| message | string | Không | Một số controller truyền message |
| data | object/array | Tùy endpoint | Dữ liệu trả về từ service |
| pagination | object | Với list | Cursor/offset pagination |
{
"success": true,
"data": {
"module": "ai",
"endpoint": "/api/v1/ai/caption"
}
}
Lỗi có thể xảy ra
| HTTP Status | Error Code | Khi nào xảy ra | Cách xử lý ở client |
|---|
| 401 | UNAUTHORIZED | Unauthorized | Login lại hoặc refresh token. |
| 400 | VALIDATION_FAILED | Validation failed | Client sửa field sai. |
| 404 | NOT_FOUND | Resource not found | Refresh dữ liệu. |
| 403 | FORBIDDEN | Forbidden | Ẩn action trong UI. |
| 500 | INTERNAL_SERVER_ERROR | External dependency fail | On-call kiểm tra provider/log. |
Ví dụ lỗi
{
"success": false,
"message": "Validation failed"
}
Ghi chú
- Endpoint đi qua global
apiLimiter. - Idempotency không được đảm bảo trừ khi service có upsert/unique constraint riêng.
- Public AI endpoints là stubs.
POST /api/v1/ai/smart-reply
POST Auth required apiLimiter
Endpoint này dùng để generate smart reply. [CẦN XÁC NHẬN] stub. Gọi endpoint này khi client cần thao tác đúng phạm vi module ai.
Request
| Header | Giá trị | Bắt buộc | Mô tả |
|---|
| Authorization | Bearer accessToken | Có | JWT access token nếu route protected |
| x-refresh-token | raw refresh token | Không | Refresh token header theo middleware |
| Parameter | Kiểu | Mô tả | Ví dụ |
|---|
| path params | string | Các phần :publicId, :username, :code nếu path có | cm123 |
| query params | string/number | take, after, page, limit hoặc module-specific query | take=20 |
| Field | Kiểu | Bắt buộc | Validation | Mô tả | Ví dụ giá trị |
|---|
| body | object | Tùy endpoint | Theo DTO Zod nếu route có validate() | Payload nghiệp vụ của endpoint | {"content":"Hello"} |
Ví dụ request
curl -X POST http://localhost:3302/api/v1/ai/smart-reply \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json"
Response
200/201 — Thành công
| Field | Kiểu | Luôn có? | Mô tả |
|---|
| success | boolean | Có | true khi request thành công |
| message | string | Không | Một số controller truyền message |
| data | object/array | Tùy endpoint | Dữ liệu trả về từ service |
| pagination | object | Với list | Cursor/offset pagination |
{
"success": true,
"data": {
"module": "ai",
"endpoint": "/api/v1/ai/smart-reply"
}
}
Lỗi có thể xảy ra
| HTTP Status | Error Code | Khi nào xảy ra | Cách xử lý ở client |
|---|
| 401 | UNAUTHORIZED | Unauthorized | Login lại hoặc refresh token. |
| 400 | VALIDATION_FAILED | Validation failed | Client sửa field sai. |
| 404 | NOT_FOUND | Resource not found | Refresh dữ liệu. |
| 403 | FORBIDDEN | Forbidden | Ẩn action trong UI. |
| 500 | INTERNAL_SERVER_ERROR | External dependency fail | On-call kiểm tra provider/log. |
Ví dụ lỗi
{
"success": false,
"message": "Validation failed"
}
Ghi chú
- Endpoint đi qua global
apiLimiter. - Idempotency không được đảm bảo trừ khi service có upsert/unique constraint riêng.
- Public AI endpoints là stubs.
GET /api/v1/ai/recommendations
GET Auth required apiLimiter
Endpoint này dùng để recommendations. [CẦN XÁC NHẬN] stub. Gọi endpoint này khi client cần thao tác đúng phạm vi module ai.
Request
| Header | Giá trị | Bắt buộc | Mô tả |
|---|
| Authorization | Bearer accessToken | Có | JWT access token nếu route protected |
| x-refresh-token | raw refresh token | Không | Refresh token header theo middleware |
| Parameter | Kiểu | Mô tả | Ví dụ |
|---|
| path params | string | Các phần :publicId, :username, :code nếu path có | cm123 |
| query params | string/number | take, after, page, limit hoặc module-specific query | take=20 |
| Field | Kiểu | Bắt buộc | Validation | Mô tả | Ví dụ giá trị |
|---|
| body | object | Không | Theo DTO Zod nếu route có validate() | Payload nghiệp vụ của endpoint | {"content":"Hello"} |
Ví dụ request
curl -X GET http://localhost:3302/api/v1/ai/recommendations \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json"
Response
200/201 — Thành công
| Field | Kiểu | Luôn có? | Mô tả |
|---|
| success | boolean | Có | true khi request thành công |
| message | string | Không | Một số controller truyền message |
| data | object/array | Tùy endpoint | Dữ liệu trả về từ service |
| pagination | object | Với list | Cursor/offset pagination |
{
"success": true,
"data": {
"module": "ai",
"endpoint": "/api/v1/ai/recommendations"
}
}
Lỗi có thể xảy ra
| HTTP Status | Error Code | Khi nào xảy ra | Cách xử lý ở client |
|---|
| 401 | UNAUTHORIZED | Unauthorized | Login lại hoặc refresh token. |
| 400 | VALIDATION_FAILED | Validation failed | Client sửa field sai. |
| 404 | NOT_FOUND | Resource not found | Refresh dữ liệu. |
| 403 | FORBIDDEN | Forbidden | Ẩn action trong UI. |
| 500 | INTERNAL_SERVER_ERROR | External dependency fail | On-call kiểm tra provider/log. |
Ví dụ lỗi
{
"success": false,
"message": "Validation failed"
}
Ghi chú
- Endpoint đi qua global
apiLimiter. - Idempotency không được đảm bảo trừ khi service có upsert/unique constraint riêng.
- Public AI endpoints là stubs.