Skip to content

[DOCS] ag-ui headless stream gains per-step token_usage custom event #700

Closed

Description

Summary

infer headless --format ag-ui (inference-gateway/cli PR #1254, fixing inference-gateway/cli#1253) now emits a per-step AG-UI CUSTOM event named token_usage after every LLM step. Its value carries the same cumulative session stats object as the terminal RUN_FINISHED result: inputTokens, outputTokens, cacheReadTokens, totalToolCalls, lastInputTokens, contextWindow, cost. The CLI's own contract page (docs/ag-ui-output.md in the cli repo) is updated in that PR; the org docs pages covering headless output and the AG-UI stream should mention the new event as well.

Acceptance Criteria

  • The AG-UI output documentation mentions the per-step token_usage custom event and its cadence (after each LLM step, before tool execution continues).
  • The documented value keys match the RUN_FINISHED result keys, including contextWindow being omitted when the model's window is unknown.
  • Any headless output / streaming examples showing usage stats are updated to reflect streaming cumulative usage.

Reference: inference-gateway/cli#1254

Activity

  1. added
    documentation
    on Sep 20, 2026
  2. added theissue type on Sep 20, 2026
  3. edenreich commented on Sep 20, 2026

    @edenreich
    Contributor

    @infer Can you work on this? use /ponytail:ponytail

  4. moved this to Todo in 2026on Sep 20, 2026
  5. inference-gateway-maintainer commented on Sep 20, 2026

    @inference-gateway-maintainer
    ContributorAuthor

    Model: ollama_cloud/glm-5.3-flash · View Job

    Todos

    • Add issue 700 to Roadmap board as In progress
    • Create and push fix/issue-700 branch
    • Read cli PR 1254 for exact token_usage event contract
    • Locate and update AG-UI/headless docs pages
    • Validate: lint:md, format:check, build
    • Commit, push, open draft PR, set board QA

    Pull Request

    #701

    ✅ Infer Result: Success

    Done. PR: #701 (ready for review)

    What changed - cli.md only (the only page in this repo covering the ag-ui headless stream; cli-judge-mode.md and opentask.md show no usage stats, so they needed nothing):

    • The ag-ui --format bullet now mentions the token_usage custom event.
    • The "AG-UI RUN_FINISHED result" section documents the per-step event: emitted after every LLM step before tool execution continues, value keys identical to the RUN_FINISHED result (including contextWindow omitted when the model's window is unknown), suppressed until the session has made a model request, plus a full example event mirrored from cli PR 1254's contract.
    • The AG-UI consumer guidance now points at the streamed per-step stats (live indicators stay current during the run instead of jumping at RUN_FINISHED).

    Skipped: no edits to the json-format session_stats example or the json assistant token_usage row - those describe the json stream and are unaffected by the ag-ui event; the existing json stream already documents per-turn usage. No docs ticket needed (this run is itself the docs change); no downstream impact beyond the linked cli PR.

    Validated: bun run lint:md, bun run format:check, bun run build all pass; commit 6d53ea2 pushed to fix/issue-700, tree clean. Issue moved to QA on the Roadmap 2026 board.

    Model: ollama_cloud/glm-5.3-flash · Exit Code: 0 · Duration: 2m 38s

    Tokens: 832,866 in · 6,815 out · 839,681 total (23 requests)

    Tool calls: 33 total · 100% success rate

    Traces
    Session: 1789902753-b71a05d9
    
    session (headless, success)                                                                        2m31s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.4s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.4s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.4s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.4s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.4s [error: *errors.errorString]
    ├── execute_tool Read call_zlq9qwl0                                                                171µs
    ├── execute_tool Bash call_xkjx929i                                                                417ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 3.4s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.4s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.4s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.4s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.4s [error: *errors.errorString]
    ├── execute_tool TodoWrite call_ny4sthuo                                                            57µs
    ├── execute_tool Bash call_7bq6o9f4                                                                 1.4s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.5s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.5s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.5s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.5s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.5s [error: *errors.errorString]
    ├── execute_tool Bash call_htx2yosf                                                                 59ms
    ├── execute_tool Bash call_dz6mz0we                                                                746ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.5s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.4s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.4s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.4s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.4s [error: *errors.errorString]
    ├── execute_tool Grep call_043zxvg4                                                                 1.5s
    ├── execute_tool Bash call_sbybdaaz                                                                366ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.8s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.8s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.8s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.8s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.8s [error: *errors.errorString]
    ├── execute_tool Grep call_zf7qnv93                                                                 12ms
    ├── execute_tool Bash call_aj5txjsg                                                                724ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.7s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.7s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.7s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.7s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.7s [error: *errors.errorString]
    ├── execute_tool Read call_lq7ujz01                                                                211µs
    ├── chat ollama_cloud/glm-5.3-flash                                                                 4.5s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       4.5s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     4.4s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             4.4s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 4.4s [error: *errors.errorString]
    ├── execute_tool Grep call_ejqclskl                                                                 1.0s
    ├── chat ollama_cloud/glm-5.3-flash                                                                14.7s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                      14.7s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    14.7s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            14.7s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                14.7s [error: *errors.errorString]
    ├── execute_tool TodoWrite call_xjj2jb32                                                            60µs
    ├── execute_tool MultiEdit call_8aw6u157                                                             1ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.5s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.5s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.5s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.5s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.5s [error: *errors.errorString]
    ├── execute_tool Bash call_h1ospnbi                                                                 1.3s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.4s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.4s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.4s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.4s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.4s [error: *errors.errorString]
    ├── execute_tool Bash call_u1z24qhg                                                                 3.3s [error: tool_error]
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.8s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.8s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.8s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.8s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.8s [error: *errors.errorString]
    ├── execute_tool Bash call_ug30k3pi                                                                 3.3s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.0s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.0s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.0s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.0s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.0s [error: *errors.errorString]
    ├── execute_tool Bash call_y84hspwq                                                                  7ms
    ├── execute_tool Bash call_s5q7t8t3                                                                 3.3s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.9s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.9s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.9s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.9s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.9s [error: *errors.errorString]
    ├── execute_tool Bash call_mud2tyiv                                                                25.3s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 2.8s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.8s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.8s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.8s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.8s [error: *errors.errorString]
    ├── execute_tool Bash call_7kmhfxtg                                                                  6ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.9s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.9s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.9s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.9s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.9s [error: *errors.errorString]
    ├── execute_tool Bash call_aex5vzya                                                                  6ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.5s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.5s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.5s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.5s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.5s [error: *errors.errorString]
    ├── execute_tool Bash call_bwy6zqvc                                                                 1.5s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 7.6s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       7.5s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     7.5s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             7.5s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 7.5s [error: *errors.errorString]
    ├── execute_tool Write call_8xtkomp0                                                               918µs
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.8s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.7s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.7s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.7s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.7s [error: *errors.errorString]
    ├── execute_tool Bash call_o3fmvwg0                                                                 1.6s
    ├── chat ollama_cloud/glm-5.3-flash                                                                 5.2s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.1s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.1s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             5.1s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.1s [error: *errors.errorString]
    ├── execute_tool Bash call_bmkniptl                                                                698ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 3.1s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.1s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.1s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.1s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.1s [error: *errors.errorString]
    ├── execute_tool Memory call_2z4urz0m                                                               1.1s
    ├── execute_tool Bash call_eo9mjes7                                                                834ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                 1.8s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.7s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.7s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.7s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.7s [error: *errors.errorString]
    ├── execute_tool Bash call_p2fiskcc                                                                  5ms
    ├── execute_tool Bash call_8fu9vkpr                                                                  5ms
    ├── execute_tool Bash call_a4nlbjmf                                                                350ms
    ├── chat ollama_cloud/glm-5.3-flash                                                                25.7s
    │   ╰── POST /v1/chat/completions [inference-gateway, server]                                      25.7s
    │       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    25.6s [error: *errors.errorString]
    │           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            25.6s
    │               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                25.6s [error: *errors.errorString]
    ├── execute_tool TodoWrite call_nqso3gxo                                                            55µs
    ╰── chat ollama_cloud/glm-5.3-flash                                                                 4.4s
        ╰── POST /v1/chat/completions [inference-gateway, server]                                       4.4s
            ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     4.4s [error: *errors.errorString]
                ╰── POST /proxy/:provider/*path [inference-gateway, server]                             4.4s
                    ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 4.4s [error: *errors.errorString]
    
    Stats
    Tool Calls
    
    ╭───────────┬───────┬───────┬────────╮
    │ Tool      │ Calls │ Fail% │ Avg    │
    ├───────────┼───────┼───────┼────────┤
    │ Bash      │ 21    │ 5%    │ 2149ms │
    │ TodoWrite │ 3     │ 0%    │ 0ms    │
    │ Grep      │ 3     │ 0%    │ 849ms  │
    │ Read      │ 2     │ 0%    │ 0ms    │
    │ MultiEdit │ 1     │ 0%    │ 1ms    │
    │ Write     │ 1     │ 0%    │ 0ms    │
    │ Memory    │ 1     │ 0%    │ 1114ms │
    ╰───────────┴───────┴───────┴────────╯
    
    Token Usage
    
    ╭────────────────────────────┬────────┬────────┬────────────┬────────┬──────╮
    │ Model                      │ Prompt │ Cached │ Completion │ Total  │ Cost │
    ├────────────────────────────┼────────┼────────┼────────────┼────────┼──────┤
    │ ollama_cloud/glm-5.3-flash │ 832866 │ 582400 │ 6815       │ 839681 │ -    │
    ╰────────────────────────────┴────────┴────────┴────────────┴────────┴──────╯
    
    Sessions
    
    ╭───────────┬──────────┬──────────╮
    │ Execution │ Mode     │ Sessions │
    ├───────────┼──────────┼──────────┤
    │ headless  │ headless │ 1        │
    ╰───────────┴──────────┴──────────╯
    

    Triggered by edenreich · Infer Action · OSS

  6. moved this from Todo to In progress in 2026on Sep 20, 2026
  7. moved this from In progress to QA in 2026on Sep 20, 2026
  8. moved this from QA to Done in 2026on Sep 20, 2026
  9. inference-gateway-releaser commented on Sep 22, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.9.14 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

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

    documentationreleased

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions