Skip to contents

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

Usage

log_ai_request(audit, step, ai_result, response_cache = NULL, ...)

Arguments

audit

An AuditLog object.

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_cache object. 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).

Value

Invisibly returns audit.

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.