Audit Logs API
Audit Log 記錄所有 API 操作,資料是 append-only,保留天數依方案而定。
| 方案 | 保留天數 | 說明 |
|---|---|---|
| Free | 7 天 | 基本操作日誌 |
| Basic | 30 天 | 操作日誌 |
| Pro | 90 天 | 合規稽核 + 匯出 |
| Business | 365 天 | AI 治理 + 防篡改 Hash Chain |
列出稽核日誌
GET /v1/audit/logs
GET /v1/audit/logs?start_time=2026-05-01T00:00:00Z&end_time=2026-05-31T23:59:59Z
Authorization: Bearer sk-your-api-key
查詢參數:
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
start_time | string | 開始時間(ISO 8601);超過方案保留天數時會自動鉗制,不回傳錯誤 | |
end_time | string | 結束時間(ISO 8601) | |
action | string | 篩選操作類型,例如 gateway.chat、rag.query、memory.write | |
page | number | 頁碼,預設 1 | |
page_size | number | 每頁筆數,預設 50,最大 100 |
回應:
{
"success": true,
"code": 1000,
"message": "Success",
"data": {
"logs": [
{
"id": "019d4c5ea1b27c3de4f56a7b8c9d0e1f",
"action": "gateway.chat",
"model_id": "openai/gpt-4o",
"project_id": "01961a3c468a7bf3b6874d59e633c850",
"gateway_id": "01961a3c5e8a7c12a4567890abcdef12",
"ip_address": "203.0.113.50",
"user_agent": "Mozilla/5.0",
"http_status": 200,
"is_success": true,
"is_cache_hit": false,
"error_code": null,
"error_msg": null,
"duration": 1523,
"credits_consumed": 0.3,
"balance_consumed_usd": 0.0143,
"tokens": {
"prompt_tokens": 1240,
"completion_tokens": 380,
"total_tokens": 1620
},
"metadata": {
"department": "legal"
},
"hash": null,
"created_at": "2026-05-08T10:30:00Z"
}
],
"total": 450,
"page": 1,
"page_size": 50
}
}
回應欄位說明:
| 欄位 | 類型 | 說明 |
|---|---|---|
id | string | Audit Log ID |
action | string | 操作類型 |
model_id | string | null | 使用的模型 ID |
project_id | string | null | 專案 ID |
gateway_id | string | null | Gateway ID |
ip_address | string | null | 來源 IP |
user_agent | string | null | User-Agent |
http_status | number | HTTP 狀態碼 |
is_success | boolean | 是否成功(HTTP 200–299) |
is_cache_hit | boolean | 是否命中 Gateway Cache |
error_code | number | null | Vecstruct 內部錯誤碼 |
error_msg | string | null | 錯誤訊息 |
duration | number | null | 執行耗時(ms) |
credits_consumed | number | Credits 消耗 |
balance_consumed_usd | number | USD 餘額消耗 |
tokens | object | null | Token 用量(僅 Gateway 操作) |
metadata | object | null | 使用者手動提供的稽核自訂標記;系統不會主動填入 |
hash | string | null | 防篡改 Hash(Business / Custom 方案) |
created_at | string | 建立時間(ISO 8601) |
取得稽核日誌詳情
GET /v1/audit/logs/{audit_id}
GET /v1/audit/logs/019d4c5ea1b27c3de4f56a7b8c9d0e1f
Authorization: Bearer sk-your-api-key
回傳單筆完整 Audit Log,除列表欄位外,還會附帶請求、回應、RAG 與 Memory 相關資料。
{
"success": true,
"code": 1000,
"message": "Success",
"data": {
"id": "019d4c5ea1b27c3de4f56a7b8c9d0e1f",
"action": "gateway.chat",
"model_id": "openai/gpt-4o",
"project_id": "01961a3c468a7bf3b6874d59e633c850",
"gateway_id": "01961a3c5e8a7c12a4567890abcdef12",
"ip_address": "203.0.113.50",
"user_agent": "Mozilla/5.0",
"http_status": 200,
"is_success": true,
"is_cache_hit": false,
"error_code": null,
"error_msg": null,
"duration": 1523,
"credits_consumed": 0.3,
"balance_consumed_usd": 0.0143,
"tokens": {
"prompt_tokens": 1240,
"completion_tokens": 380,
"total_tokens": 1620
},
"metadata": {
"department": "legal"
},
"request_body": {
"model": "openai/gpt-4o",
"messages": [
{
"role": "user",
"content": "Docker 和虛擬機的差異?"
}
]
},
"response_body": null,
"input_content": [
{
"role": "user",
"content": "Docker 和虛擬機的差異?"
}
],
"output_content": "Docker 基於 Linux namespace + cgroup,啟動速度更快…",
"rag_query": ["Docker 和虛擬機的差異"],
"rag_results": [
{
"content": "Docker 基於 Linux namespace...",
"similarity": 0.91,
"source": {
"document_id": "019373a01a2b7c3d4e5f6a7b8c9d0e1f",
"name": "container-guide.pdf",
"mime_type": "application/pdf",
"file_size": 204800
}
}
],
"memory_query": ["使用者最後一句訊息"],
"memory_results": [
{
"id": "019449a012347abc8def0123456789ab",
"content": "使用者偏好繁體中文",
"memory_type": "rule",
"importance": 0.9,
"similarity": 0.87,
"final_score": 0.87,
"source": "semantic"
}
],
"hash": null,
"created_at": "2026-05-08T10:30:00Z"
}
}
詳情額外欄位:
| 欄位 | 類型 | 說明 |
|---|---|---|
request_body | object | null | 完整 API 請求 Body |
response_body | object | null | 完整 API 回應 Body;串流請求通常為 null |
input_content | object | array | null | 抽出後的輸入內容,例如 Chat messages |
output_content | string | object | null | 抽出後的輸出內容 |
rag_query | string[] | null | [0] 為原始查詢,[1:] 為 Query Expansion 擴展查詢 |
rag_results | object[] | null | 命中文件摘要,含 content、similarity、source |
memory_query | string[] | null | Memory 查詢或輸入內容;delete 和 list 這類操作為 null |
memory_results | object[] | null | Memory 搜尋結果或 CRUD 結果 |
找不到資料或非本人擁有時回傳 404。
匯出稽核日誌
POST /v1/audit/logs/export
Pro+ 方案限定。端點會先建立匯出任務並回傳 export_id,目前初始狀態為 processing,download_url 會先是 null。
POST /v1/audit/logs/export
Authorization: Bearer sk-your-api-key
Content-Type: application/json
{
"format": "csv",
"start_time": "2026-05-01T00:00:00Z",
"end_time": "2026-05-31T23:59:59Z"
}
請求欄位:
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
start_time | string | ✓ | 開始時間(ISO 8601) |
end_time | string | ✓ | 結束時間(ISO 8601) |
format | string | 匯出格式:csv(預設)或 json |
回應:
{
"success": true,
"code": 1000,
"message": "Success",
"data": {
"export_id": "019d4c5e-a1b2-7c3d-e4f5-6a7b8c9d0e1f",
"status": "processing",
"estimated_records": 4500,
"download_url": null
}
}
錯誤碼
| 錯誤碼 | HTTP | 說明 |
|---|---|---|
| 2200 | 403 | Audit Log 功能需要有效訂閱 |
| 2201 | 400 | 匯出時間範圍超過方案保留天數 |
| 2202 | 403 | 匯出功能需 Pro+ 方案 |
| 2203 | 409 | 匯出任務進行中 |
所需權限
| 操作 | 所需權限 |
|---|---|
| 讀取稽核日誌 | audit.read |
| 匯出稽核日誌 | audit.export(Pro+ 方案) |