---
title: "Log every model call · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback/log-model-calls
updated: 2026-10-20
licence: "All rights reserved"
---

# Log every model call

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Logs, privacy and feedback](https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback)
- Rule: Write one structured log line per model call. It holds the feature, request ID, prompt ID and version, model version, tokens, cost, latency, ending and outcome.
- How: Write the line in the [model gateway](https://agentwranglers.se/playbook/ai-features/deciding-to-use-a-model/model-gateway), so no call is missed. Use the same request ID as the rest of the request, as in [tie every line to its request](https://agentwranglers.se/playbook/operations/logs/request-ids). Leave the prompt and answer text out of this line. They go to a separate store with its own limits, as the next rule shows. Return a call ID to the feature, so feedback can point at the exact call.
- Check: Parse one hour of gateway logs with a JSON tool. Every `ai.call` line has all the listed fields, and none contains a field holding prompt or answer text.

Example:

```json
{"time":"2026-10-20T09:15:04.120Z","level":"info","event":"ai.call","request_id":"7f3c2a9e","call_id":"c_81f2","feature":"return-assistant","prompt_id":"return-assistant","prompt_version":7,"model":"example-model-2026-05-14","input_tokens":1840,"cached_input_tokens":1536,"output_tokens":212,"cost_usd":0.0013,"latency_ms":1420,"ending":"complete","outcome":"shown"}
```

```ts
log.info({ event: 'ai.call', requestId, callId, feature, promptId: prompt.id, promptVersion: prompt.version, model: response.model,
  inputTokens: usage.inputTokens, cachedInputTokens: usage.cachedInputTokens, outputTokens: usage.outputTokens,
  costUsd: callCostUsd(response.model, usage), latencyMs, ending, outcome });
```

```python
log.info("ai.call", request_id=request_id, call_id=call_id, feature=feature, prompt_id=prompt.id, prompt_version=prompt.version,
         model=response.model, input_tokens=usage.input_tokens, cached_input_tokens=usage.cached_input_tokens,
         output_tokens=usage.output_tokens, cost_usd=call_cost_usd(response.model, usage),
         latency_ms=latency_ms, ending=ending, outcome=outcome)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback/log-model-calls`.

- Next: [Keep prompt and answer text briefly and apart](https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback/prompt-text-retention)
- [Logs, privacy and feedback](https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback)
