Skip to content

feat: Add id and finish_reason to ModelResponse #2325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fatelei
Copy link

@fatelei fatelei commented Jul 27, 2025

Feature:

Fixes #886

@fatelei fatelei force-pushed the issue-886 branch 2 times, most recently from 7a34524 to bacbc82 Compare July 28, 2025 10:38
@@ -792,6 +792,12 @@ class ModelResponse:
vendor_id: str | None = None
"""Vendor ID as specified by the model provider. This can be used to track the specific request to the model."""

id: str | None = None
"""Unique identifier for the model response, e.g. as returned by the model provider (OpenAI, etc)."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor_id already exists for this same purpose, so we don't need a new field. Can you rename vendor_id to id? Note that this is a public class, so we'll need to continue supporting getting and setting vendor_id with a deprecation warning.

I'm also OK keeping it as vendor_id.


finish_reason: str | None = None
"""The reason the model finished generating this response, e.g. 'stop', 'length', etc."""

def otel_events(self, settings: InstrumentationSettings) -> list[Event]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue mentions:

These fields would be used to populate gen_ai.response.id and gen_ai.response.finish_reasons in opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans#genai-attributes

Can you please handle that here as well so this PR can close that issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that genai.response.finish_reasons has specific allowed values: #1882 (comment)

I also left some other related suggestions on that older PR that tried to add finish_reason -- can you please check those out as well?

id: str | None = None
"""Unique identifier for the model response, e.g. as returned by the model provider (OpenAI, etc)."""

finish_reason: str | None = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're already storing finish_reason in the vendor_details dict in various places, can you please update those to also set this property? We'll want to keep it in vendor_details as well for backward compatibility.

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.

Add id and finish_reason to ModelResponse
2 participants