Skip to content

server: add timings block to OpenAI-compatible responses (#342)#572

Open
Mike014 wants to merge 1 commit into
antirez:mainfrom
Mike014:feature/342-timings-json
Open

server: add timings block to OpenAI-compatible responses (#342)#572
Mike014 wants to merge 1 commit into
antirez:mainfrom
Mike014:feature/342-timings-json

Conversation

@Mike014

@Mike014 Mike014 commented Jul 17, 2026

Copy link
Copy Markdown

What this does

Exposes prompt/decode timing stats in a top-level timings object,
sibling to usage, matching the llama.cpp-style format requested in #342:
cache_n, prompt_n, prompt_ms, prompt_per_token_ms,
prompt_per_second, predicted_n, predicted_ms,
predicted_per_token_ms, predicted_per_second.

Covers both blocking and streaming (stream_include_usage-gated)
OpenAI-compatible responses.

Scope note

append_openai_timings_json is also exercised by the legacy
/v1/completions path via final_response, not only
/v1/chat/completions as literally scoped in #342 — this matches
llama.cpp's behavior, flagging it here for visibility in case that's
not the intended scope.

Testing

  • make cpu: clean build, -Wall -Wextra, zero warnings
  • ./ds4_test --server: pass, including two new tests
    (test_openai_stream_usage_reports_cache_details extended,
    test_openai_timings_zero_division added — verifies no NaN/Inf/malformed
    JSON when completion_tokens=0 or cache_read_tokens=0)
  • No model/GPU available in my dev environment (CPU-only); production
    backend (Metal/CUDA) not exercised — flagging for maintainer
    verification before merge
  • Speed track (ds4-bench) not applicable: no inference-path or kernel
    code touched, only response serialization plus two now_sec() calls
    outside the decode loop

AI assistance disclosure

Development assisted by Claude (Anthropic) and Fable 5 — I reviewed and
verified every changed line, ran the tests above myself, and traced the
call chain by hand before implementing. Happy to walk through any part
of the diff in more detail.

Closes #342

Expose prompt/decode timing stats in a top-level 'timings' object,
sibling to 'usage', matching the llama.cpp-style format requested in
prompt_per_second, predicted_n, predicted_ms, predicted_per_token_ms,
predicted_per_second. Covers both blocking and streaming
(stream_include_usage-gated) responses.

Note: append_openai_timings_json is also exercised by the legacy
/v1/completions path via final_response, not only /v1/chat/completions
as literally scoped in antirez#342 -- matches llama.cpp behavior, flagging
for visibility.

Testing:
- make cpu: clean build, -Wall -Wextra, zero warnings
- ./ds4_test --server: pass, including two new tests
  (test_openai_stream_usage_reports_cache_details extended,
  test_openai_timings_zero_division added)
- No model/GPU available on this machine (CPU-only dev environment);
  production backend (Metal/CUDA) not exercised, flagging for
  maintainer verification
- Speed track (ds4-bench) not applicable: no inference-path or kernel
  code touched, only response serialization and two now_sec() calls
  outside the decode loop

Signed-off-by: mike014 <mikgrimaldi7@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: more information in usage

1 participant