Skip to content

feat(gemini): expose finish_reason and model_version on StreamingCompletionResponse#1776

Merged
gold-silver-copper merged 3 commits into
mainfrom
mateobelanger/gemini-stream-metadata
May 16, 2026
Merged

feat(gemini): expose finish_reason and model_version on StreamingCompletionResponse#1776
gold-silver-copper merged 3 commits into
mainfrom
mateobelanger/gemini-stream-metadata

Conversation

@mateobelanger
Copy link
Copy Markdown
Member

@mateobelanger mateobelanger commented May 16, 2026

Summary

  • Adds finish_reason: Option<FinishReason> and model_version: Option<String> to gemini::streaming::StreamingCompletionResponse — both were deserialized from the SSE stream but dropped before the FinalResponse was yielded to callers
  • Adds model_version: Option<String> to gemini::interactions_api::streaming::StreamingCompletionResponse, extracted from Interaction.model
  • Fixes a subtle bug: when the final Gemini chunk carries finishReason with no content (a common protocol pattern), the stream now correctly breaks instead of continuing to wait for more events
  • The Interactions API has no FinishReason equivalent (it uses InteractionStatus lifecycle values); only model_version is added for that path, with a doc comment explaining why

Motivation

Ryzome's PostHog LLM Analytics forwarder needs $ai_stop_reason (from finish_reason) and the resolved model string $ai_model (from model_version, which is the exact model like gemini-2.5-pro-preview-05-06 rather than the alias the caller requested).

Test Plan

  • New unit test test_streaming_completion_response_has_finish_reason_and_model_version in gemini/streaming.rs asserts both fields populate and roundtrip through serde correctly
  • New unit test test_streaming_completion_response_has_model_version in interactions_api/streaming.rs asserts model_version populates and roundtrips

Closes RIG-1315

mateobelanger and others added 2 commits May 15, 2026 22:44
…letionResponse

Both fields were being deserialized from the Gemini SSE stream but dropped
before the FinalResponse was yielded to callers. Surfaces them for PostHog
LLM Analytics ($ai_stop_reason, $ai_model).

Also fixes a subtle bug: when the final chunk carries finishReason without
content (common in Gemini's streaming protocol), the stream now correctly
breaks instead of continuing to wait for more events.

RIG-1315

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nResponse

The Interactions API does not have a FinishReason equivalent (uses
InteractionStatus lifecycle values instead). Surfaces model_version
extracted from Interaction.model for symmetry with the Generate Content
streaming path.

RIG-1315

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 16, 2026

RIG-1315

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gold-silver-copper
Copy link
Copy Markdown
Contributor

LGTM, gonna add a live regression test as a follow up PR

@gold-silver-copper gold-silver-copper added this pull request to the merge queue May 16, 2026
Merged via the queue into main with commit 327e4d4 May 16, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants