Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Response Text Done Event

From Leeroopedia
Revision as of 13:40, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Response_Text_Done_Event.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains API_Types, Responses_API
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete type for representing an event emitted when text content output is finalized during streaming, provided by the openai-python SDK.

Description

ResponseTextDoneEvent is a Pydantic model representing the response.output_text.done streaming event. It is emitted when the model has finished generating a text output content part. The event carries the complete text, a logprobs list of Logprob objects (each containing token, logprob, and optional top_logprobs), and positional fields content_index, item_id, output_index, and sequence_number. The module also defines supporting classes Logprob and LogprobTopLogprob.

Usage

Import this type when you need to capture the finalized text output along with its log probabilities from a streaming response.

Code Reference

Source Location

Signature

class ResponseTextDoneEvent(BaseModel):
    """Emitted when text content is finalized."""

    content_index: int
    item_id: str
    logprobs: List[Logprob]
    output_index: int
    sequence_number: int
    text: str
    type: Literal["response.output_text.done"]

Import

from openai.types.responses import ResponseTextDoneEvent

I/O Contract

Fields

Name Type Required Description
content_index int Yes The index of the content part that the text content is finalized.
item_id str Yes The ID of the output item that the text content is finalized.
logprobs List[Logprob] Yes The log probabilities of the tokens. Each Logprob has token (str), logprob (float), and optional top_logprobs (List[LogprobTopLogprob]).
output_index int Yes The index of the output item that the text content is finalized.
sequence_number int Yes The sequence number for this event.
text str Yes The text content that is finalized.
type Literal["response.output_text.done"] Yes The type of the event. Always response.output_text.done.

Usage Examples

import openai

client = openai.OpenAI()

stream = client.responses.create(
    model="gpt-4o",
    input="What is the capital of France?",
    stream=True,
)

for event in stream:
    if event.type == "response.output_text.done":
        print(f"Final text: {event.text}")
        if event.logprobs:
            for lp in event.logprobs[:5]:
                print(f"  Token: {lp.token!r}, logprob: {lp.logprob:.4f}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment