Record an AI request with the structured response from ai_complete
Source: R/audit_log.R
log_ai_request.RdConvenience wrapper around log_ai_decision that records an
"ai_request" decision and unpacks the structured fields from
ai_complete's return value into the audit record:
model, finish_reason, prompt_hash, request_id, and per-record token usage.
Arguments
- audit
An
AuditLogobject.- step
Pipeline step (e.g.,
"coding","sentiment"). Must be one of.valid_audit_steps.- ai_result
The list returned by
ai_complete.- response_cache
Optional
init_response_cacheobject. When provided, the raw_response is written to the cache and the path is recorded in the JSONL record.- ...
Additional caller-specific named fields to include in the record (e.g.,
entry_id = "abc",batch_idx = 3).
Details
If a ResponseCache is provided, the
raw_response is also written to the cache (content-addressable by
prompt_hash) and the cache path is recorded in the audit log entry.
This separation keeps the JSONL file lightweight while preserving the full
API response for replay.
Silently no-ops on NULL ai_result (e.g., when ai_complete
threw and the caller's tryCatch returned NULL) so callers can wrap calls in
tryCatch and still call log_ai_request unconditionally.