[GH-ISSUE #14680] OpenAPI spec: ChatStreamEvent missing usage fields in final chunk #56014

Open
opened 2026-04-29 10:08:38 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @davidmigloz on GitHub (Mar 6, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/14680

Description

The OpenAPI spec at docs/openapi.yaml defines ChatStreamEvent with only 4 fields: model, created_at, message, done.

However, the Ollama API sends additional usage/timing fields in the final streaming chunk (when done: true), just like it does for GenerateStreamEvent and ChatResponse. These fields are missing from the ChatStreamEvent schema:

  • done_reason
  • total_duration
  • load_duration
  • prompt_eval_count
  • prompt_eval_duration
  • eval_count
  • eval_duration

Current state

Schema Has usage fields?
GenerateResponse
GenerateStreamEvent
ChatResponse
ChatStreamEvent (missing)

Expected

ChatStreamEvent should include the same usage fields as GenerateStreamEvent, since the API returns them in the final chunk.

Impact

SDK generators that rely on the OpenAPI spec produce types that can't capture usage metrics from chat streaming responses, forcing users to bypass the typed API and parse raw NDJSON.

Originally created by @davidmigloz on GitHub (Mar 6, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/14680 ## Description The OpenAPI spec at `docs/openapi.yaml` defines `ChatStreamEvent` with only 4 fields: `model`, `created_at`, `message`, `done`. However, the Ollama API sends additional usage/timing fields in the **final streaming chunk** (when `done: true`), just like it does for `GenerateStreamEvent` and `ChatResponse`. These fields are missing from the `ChatStreamEvent` schema: - `done_reason` - `total_duration` - `load_duration` - `prompt_eval_count` - `prompt_eval_duration` - `eval_count` - `eval_duration` ## Current state | Schema | Has usage fields? | |---|---| | `GenerateResponse` | ✅ | | `GenerateStreamEvent` | ✅ | | `ChatResponse` | ✅ | | `ChatStreamEvent` | ❌ (missing) | ## Expected `ChatStreamEvent` should include the same usage fields as `GenerateStreamEvent`, since the API returns them in the final chunk. ## Impact SDK generators that rely on the OpenAPI spec produce types that can't capture usage metrics from chat streaming responses, forcing users to bypass the typed API and parse raw NDJSON.
GiteaMirror added the documentation label 2026-04-29 10:08:38 -05:00
Author
Owner

@davidmigloz commented on GitHub (Mar 6, 2026):

For reference, the Go code uses a single ChatResponse struct for both streaming and non-streaming responses (api/types.go), which includes:

  • Embedded Metrics struct (total_duration, load_duration, prompt_eval_count, prompt_eval_duration, eval_count, eval_duration)
  • done_reason
  • logprobs

So the OpenAPI spec's ChatStreamEvent should match ChatResponse (minus any non-streaming-only fields), just like GenerateStreamEvent matches GenerateResponse.

logprobs is also missing from ChatStreamEvent in the spec but present in GenerateStreamEvent.

<!-- gh-comment-id:4014789456 --> @davidmigloz commented on GitHub (Mar 6, 2026): For reference, the Go code uses a single `ChatResponse` struct for both streaming and non-streaming responses ([api/types.go](https://github.com/ollama/ollama/blob/main/api/types.go)), which includes: - Embedded `Metrics` struct (`total_duration`, `load_duration`, `prompt_eval_count`, `prompt_eval_duration`, `eval_count`, `eval_duration`) - `done_reason` - `logprobs` So the OpenAPI spec's `ChatStreamEvent` should match `ChatResponse` (minus any non-streaming-only fields), just like `GenerateStreamEvent` matches `GenerateResponse`. `logprobs` is also missing from `ChatStreamEvent` in the spec but present in `GenerateStreamEvent`.
Author
Owner

@kanusahai commented on GitHub (Mar 8, 2026):

Hello, can I take this up ?

<!-- gh-comment-id:4018367716 --> @kanusahai commented on GitHub (Mar 8, 2026): Hello, can I take this up ?
Author
Owner

@Rishi-11-2 commented on GitHub (Mar 8, 2026):

Hi I have opened a Pull Request for the same .
can you review it : https://github.com/ollama/ollama/pull/14717/commits

<!-- gh-comment-id:4018932420 --> @Rishi-11-2 commented on GitHub (Mar 8, 2026): Hi I have opened a Pull Request for the same . can you review it : https://github.com/ollama/ollama/pull/14717/commits
Author
Owner

@Rishi-11-2 commented on GitHub (Mar 9, 2026):

@davidmigloz please review my pr and do I need to anything else or improve it. Thank you

<!-- gh-comment-id:4023288826 --> @Rishi-11-2 commented on GitHub (Mar 9, 2026): @davidmigloz please review my pr and do I need to anything else or improve it. Thank you
Author
Owner

@kanusahai commented on GitHub (Mar 10, 2026):

It seems like @Rishi-11-2 got to it sooner. His change LGTM but I'll let @davidmigloz review.

<!-- gh-comment-id:4028485042 --> @kanusahai commented on GitHub (Mar 10, 2026): It seems like @Rishi-11-2 got to it sooner. His change LGTM but I'll let @davidmigloz review.
Author
Owner

@davidmigloz commented on GitHub (Mar 10, 2026):

Thanks for the PR! I've posted my feedback there

<!-- gh-comment-id:4029799194 --> @davidmigloz commented on GitHub (Mar 10, 2026): Thanks for the PR! I've posted my feedback there
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#56014