Skip to content

[DOCS] Document the agent stream session_stats summary line #85

Closed

Description

@edenreich

Summary

infer agent (the headless JSON-line stream mode of the CLI) now emits a final session_stats line when a session completes, summarizing token usage and dollar cost. This lets stream consumers (e.g. inference-gateway/infer-action) report real run cost without re-implementing the per-model pricing table.

Example line:

{"type":"session_stats","message":"Session complete","timestamp":"2026-05-29T17:48:55+02:00","model":"deepseek/deepseek-v4-flash","prompt_tokens":21000,"completion_tokens":1260,"total_tokens":22260,"requests":7,"cost":{"input":0.0021,"output":0.0008,"total":0.0029,"currency":"USD"}}

Fields to document:

  • type: always session_stats.
  • message: human-readable status ("Session complete").
  • model: the model used for the run.
  • prompt_tokens / completion_tokens / total_tokens: summed across all turns/requests in the run.
  • requests: number of LLM requests (turns that reported usage).
  • cost: object with input, output, total, and currency (default USD). Computed from the configured pricing table; values are zeros when pricing.enabled: false.

Behavior notes:

  • Additive and emitted once at session completion; consumers should ignore unknown stream type values.
  • Always emitted in agent mode (no flag).
  • Single model per run (cost is attributed to the run's model).

Source: inference-gateway/cli PR #553, issue inference-gateway/cli#552.

Acceptance Criteria

  • Document the session_stats stream line on the CLI agent / headless stream-output reference page.
  • Describe each field and the nested cost object, including currency and the pricing-disabled (zeros) behavior.
  • Note that the line is additive, emitted once on completion, and that consumers should ignore unknown type values.

Activity

  1. added
    documentation
    on May 29, 2026
  2. edenreich commented on May 29, 2026

    @edenreich
    ContributorAuthor

    @claude Can you document it? use /maintainer

  3. added theissue type on May 29, 2026
  4. claude commented on May 29, 2026

    @claude
    Contributor

    Claude finished @edenreich's task in 4m 13s —— View job • claude/issue-85-20260529-1605 • Create PR ➔


    Task: Document the session_stats stream line

    • Read repo conventions (CLAUDE.md) and follow maintainer skill
    • Locate the CLI agent / headless stream-output reference page
    • Check sidebar config and existing CLI docs structure
    • Add session_stats documentation: fields, nested cost object, behavior notes
    • Lint and format the changes (npm run lint:md, npm run format:check, npm run build all green)
    • Commit changes and provide PR URL

    Summary

    Added a new ### Headless Agent Stream Output subsection to cli.md (under Agent Modes), covering:

    • The JSONL stream contract for infer agent (one JSON object per line, type discriminator, additive, ignore-unknown-types guidance).
    • The session_stats summary line with a real example and a field-reference table for all top-level fields.
    • A nested Cost object reference table (input, output, total, currency).
    • The pricing.enabled: false zeros behavior - cost is always present so consumers get a stable schema.
    • Behavior notes: additive, emitted once on completion (including early errors), always emitted in agent mode (no flag), single model per run, ignore-unknown-types.

    The placement keeps the new headless reference adjacent to the existing interactive Agent Modes (Standard / Plan / Auto-Accept), so the page now covers both interactive and headless invocations of the agent in one spot.

    Build: npm run lint:md clean, npm run format:check clean, npm run build produces a static cli.html containing the new section.

    Cross-repo impact

    Pure docs change, scoped to inference-gateway/docs. No SDK, operator, gateway, or schemas impact.

    · branch: claude/issue-85-20260529-1605

  5. moved this to In progress in 2026on May 29, 2026
  6. added a commit that references this issue on May 29, 2026
    2ddf6f3
  7. moved this from In progress to Done in 2026on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions