跳至主要内容

Audit Logs API

Audit Log 記錄所有 API 操作,資料是 append-only,保留天數依方案而定。

方案保留天數說明
Free7 天基本操作日誌
Basic30 天操作日誌
Pro90 天合規稽核 + 匯出
Business365 天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_timestring開始時間(ISO 8601);超過方案保留天數時會自動鉗制,不回傳錯誤
end_timestring結束時間(ISO 8601)
actionstring篩選操作類型,例如 gateway.chatrag.querymemory.write
pagenumber頁碼,預設 1
page_sizenumber每頁筆數,預設 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
}
}

回應欄位說明:

欄位類型說明
idstringAudit Log ID
actionstring操作類型
model_idstring | null使用的模型 ID
project_idstring | null專案 ID
gateway_idstring | nullGateway ID
ip_addressstring | null來源 IP
user_agentstring | nullUser-Agent
http_statusnumberHTTP 狀態碼
is_successboolean是否成功(HTTP 200–299)
is_cache_hitboolean是否命中 Gateway Cache
error_codenumber | nullVecstruct 內部錯誤碼
error_msgstring | null錯誤訊息
durationnumber | null執行耗時(ms)
credits_consumednumberCredits 消耗
balance_consumed_usdnumberUSD 餘額消耗
tokensobject | nullToken 用量(僅 Gateway 操作)
metadataobject | null使用者手動提供的稽核自訂標記;系統不會主動填入
hashstring | null防篡改 Hash(Business / Custom 方案)
created_atstring建立時間(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_bodyobject | null完整 API 請求 Body
response_bodyobject | null完整 API 回應 Body;串流請求通常為 null
input_contentobject | array | null抽出後的輸入內容,例如 Chat messages
output_contentstring | object | null抽出後的輸出內容
rag_querystring[] | null[0] 為原始查詢,[1:] 為 Query Expansion 擴展查詢
rag_resultsobject[] | null命中文件摘要,含 contentsimilaritysource
memory_querystring[] | nullMemory 查詢或輸入內容;delete 和 list 這類操作為 null
memory_resultsobject[] | nullMemory 搜尋結果或 CRUD 結果

找不到資料或非本人擁有時回傳 404


匯出稽核日誌

POST /v1/audit/logs/export

Pro+ 方案限定。端點會先建立匯出任務並回傳 export_id,目前初始狀態為 processingdownload_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_timestring開始時間(ISO 8601)
end_timestring結束時間(ISO 8601)
formatstring匯出格式: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說明
2200403Audit Log 功能需要有效訂閱
2201400匯出時間範圍超過方案保留天數
2202403匯出功能需 Pro+ 方案
2203409匯出任務進行中

所需權限

操作所需權限
讀取稽核日誌audit.read
匯出稽核日誌audit.export(Pro+ 方案)