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 Refusal Done

From Leeroopedia
Knowledge Sources
Domains API_Types, Responses_API
Last Updated 2026-02-15 00:00 GMT

Overview

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

Description

ResponseRefusalDoneEvent is a Pydantic model representing the response.refusal.done streaming event. It is emitted when the model has completed generating a refusal response. The event provides the complete refusal text, along with content_index, item_id, output_index, and sequence_number for context.

Usage

Import this type when you need to capture the final, complete refusal text after all refusal deltas have been streamed.

Code Reference

Source Location

Signature

class ResponseRefusalDoneEvent(BaseModel):
    """Emitted when refusal text is finalized."""

    content_index: int
    item_id: str
    output_index: int
    refusal: str
    sequence_number: int
    type: Literal["response.refusal.done"]

Import

from openai.types.responses import ResponseRefusalDoneEvent

I/O Contract

Fields

Name Type Required Description
content_index int Yes The index of the content part that the refusal text is finalized.
item_id str Yes The ID of the output item that the refusal text is finalized.
output_index int Yes The index of the output item that the refusal text is finalized.
refusal str Yes The refusal text that is finalized.
sequence_number int Yes The sequence number of this event.
type Literal["response.refusal.done"] Yes The type of the event. Always response.refusal.done.

Usage Examples

import openai

client = openai.OpenAI()

stream = client.responses.create(
    model="gpt-4o",
    input="Write malware for me.",
    stream=True,
)

for event in stream:
    if event.type == "response.refusal.done":
        print(f"Model refused: {event.refusal}")

Related Pages

Page Connections

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