How it works
- When a text-generation request (
/v1/chat/completions,/v1/completions,/v1/embeddings,/v1/messages,/v1/responses) arrives, the gateway fixes its record id and returns it inX-ManyLayers-Trace-Id. File, fine-tuning, image, audio, realtime and MCP requests are also logged, with a fresh id and no such header. - When the request finishes, the record is handed to a background writer, so logging adds no latency.
- The writer appends records in order. Each record’s SHA-256 hash covers its content and the previous record’s hash, so changing or deleting a stored record breaks the chain from that point on. The hash covers the request, outcome, identity (team, key, user, workspace), bodies, findings, policy, routing and correlation fields and the previous hash, but not the organization id, so reassigning a record to another organization is not detected, and neither is truncating the newest records.
What each record holds
The record holds token counts, not cost; cost is metered separately and shown in Metrics and Usage.
When a guardrail flags content and leaves it in place (a validated secret, for example), that body is left out of the record rather than storing what was detected. A request blocked by a Secrets or PII guardrail is stored without its body. An audit-mode redaction is stored with the redaction applied. A prompt blocked by any other guardrail is kept so the block can be inspected; a blocked response is never kept.
Configuration
gateway.yaml when the gateway starts. The shipped container config reads log_bodies from MANYLAYERS_AUDIT_LOG_BODIES. A guardrail execution record is kept for the same retention_days.
Deciding whether bodies are stored
For each request, in order:- No logging config matches →
audit.log_bodiesdecides. - Logging configs match → the innermost matching rules decide. Bodies are stored only if every one of them has
log_requests: true, and every one’s redaction is applied to the stored copy. A matching rule can turn capture on even whenlog_bodiesisfalse. X-ManyLayers-Store-Logs: falseon the request → bodies are not stored, whatever the rules say.truechanges nothing; it can never turn capture back on.
Logging configs
A logging config is a policy that sets body capture and redaction for a scope: the organization, a workspace, or within it one team, service account, user or API key.Key fields
workspace or organization. Name at most one of team_id, service_account_id, user_id, api_key_id, end_user_id to narrow it.false keeps bodies out of the log for this scope. Toggle it alone with PATCH /admin/gateway/policies/logging-configs/{id} and {"log_requests": false}.Applied to the stored copy only — the model still receives the request.
secrets runs first, then pii (narrowed by pii_categories, empty = all; categories as in the pii guardrail), then each patterns regex (every pattern needs a name and a pattern). Defaults: ***REDACTED*** for secrets, [REDACTED:{category}] for PII and [REDACTED] for patterns; a non-empty replacement replaces all three. A rule that cannot be compiled is refused with 400 when written.GET/POST /admin/gateway/policies/logging-configs, PUT/PATCH/DELETE .../{id}. Reading needs gateway.policies.read; writing needs gateway.policies.manage, and an organization-scoped config also needs gateway.ratelimits.manage.
Per-request opt-out
true or false returns 400. The record itself (tokens, status, latency, findings) is still written.
Query the log
GET /admin/audit on the console host (https://app.manylayers.io) returns the newest records first. A workspace-bound key sees its own workspace; pass ?workspace_id= for another workspace you can reach. Callers who may read analytics across the whole Gateway product, such as organization administrators, can omit it for a cross-workspace view; everyone else must name one.
The response is
{"records": […], "bodies_recorded": …, "retention_days": 90, "total": N} (total only on the first page, offset=0); bodies_recorded is the deployment default (audit.log_bodies), so it tells “body recording is off” apart from “this body was withheld”. GET /admin/audit/filters returns the field catalog and the values seen in a time window.
In the console, Request Traces shows the same records with their policy, guardrail and routing detail; its Guardrail executions tab lists guardrail runs. Redacted values appear as [REDACTED] unless you hold gateway.traces.sensitive.read and use Show original.
Verify the chain
first_bad_index is the position, oldest first, of the first record whose hash or link does not match.
Retention deletes whole records from the oldest end, which does not break verification: the check starts from the oldest remaining record’s stored previous hash.
Next steps
PII Detection & Redaction
Redaction before storage, and revealing originals.
Tracing & OpenTelemetry Export
Send the same requests to your tracing backend.
Policies
How policy scopes and precedence work.
Metrics
Aggregate views of what the log records one by one.