The DeepSeek Harness session log as a cost record

Published 16 August 2026

Most agent cost tracking is bolted on. You wrap the provider SDK, emit a span, hope nobody adds a second call path, and discover six weeks later that the subagent traffic never got instrumented. DeepSeek Harness takes a different route: the session log is the primary artefact, and token accounting rides inside it.

The session is an append-only event log

The docs put it directly: a Session is an append-only log of typed SessionEvents, and it is the single source of truth for an agent's whole interaction history. Every event carries four fields:

FieldMeaning
typeEvent category, a key from the extensible SessionEventMap
seqMonotonic sequence number, equal to the log length at append time
timeUnix epoch milliseconds
dataType-specific, JSON-serialisable payload

Surface events carry two more: sourceEventSeqs, referencing the events they derive from, and surfaceOp, describing how the event enters the message surface.

The events a cost model cares about

That last pair is the piece most homegrown telemetry misses. request/context tells you which provider and model actually served the step, and request/header tells you what was sent. Together they let you reconstruct the cost of a step from the log alone, without trusting a separately maintained pricing lookup keyed off an assumed model.

Usage travels with output

The docs are careful about this: an assistant/message carries the step's usage when the adapter reported token accounting, so the model output and its accounting travel together. The reader prefers per-step assistant/chunk { type: 'usage' } records and falls back to assistant/message.usage.

The practical effect is that you cannot end up with orphaned usage numbers you can no longer attribute to a step, which is the single most common defect in retrofitted agent cost tracking.

Derived history, not duplicated history

Message history is derived from surface events and never stored separately. The projection rules are simple: user/message becomes a user message, assistant/message becomes an assistant message with raw chunks skipped, tool/result becomes a user message carrying a tool-result block. Everything else stays log-only.

For a FinOps team this is the useful property. There is one place to read, and reading it does not risk disagreeing with what the model actually saw.

The governing principle of the harness is "model-visible means logged" — the session log must be able to reconstitute the run. A log complete enough to replay a session is, by construction, complete enough to cost it.

What to build on top

  1. Join step/start and step/end to get step duration and count per turn. Step count per turn is your orchestration multiplier, and it is the number that surprises finance.
  2. Attach request/context to each step for the provider and model, then price the usage from the same step's assistant/chunk usage record.
  3. Count tool/call events per step. High tool-call fan-out per step is where latency and retry cost concentrate.
  4. Watch TurnEndReason distributions. Turns ending for reasons other than completion are paid-for work that produced nothing.

Related


Want this applied to your own LLM spend? FinOps LLM runs a free audit of your AI costs and shows where the savings are. Book free audit →

Back to research

FAQ

What is a session in DeepSeek Harness?

A session is an append-only log of typed SessionEvents, described in the docs as the single source of truth for an agent's whole interaction history. Message history is derived from the log rather than stored separately.

Where is token usage recorded in DeepSeek Harness?

Usage travels with model output. The system reads per-step assistant/chunk records of type 'usage', with assistant/message.usage as a fallback, so a step's token accounting and the text it produced stay attached to each other.

What does 'model-visible means logged' mean?

It is the governing principle of the harness: anything the model could see must appear in the session log, so the log can reconstitute the run. For cost work this means the log is complete by construction rather than by instrumentation discipline.