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 Delta

From Leeroopedia
Revision as of 13:40, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Response_Refusal_Delta.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 a streaming delta event emitted when partial refusal text is generated, provided by the openai-python SDK.

Description

ResponseRefusalDeltaEvent is a Pydantic model representing the response.refusal.delta streaming event. It is emitted when the model is generating a refusal response and incremental text fragments (delta) are added. The event includes content_index and output_index for positional tracking, item_id identifying the parent output item, and sequence_number for ordering.

Usage

Import this type when you need to detect and handle refusal text as it streams in, for example to display a refusal message incrementally in a chat UI.

Code Reference

Source Location

Signature

class ResponseRefusalDeltaEvent(BaseModel):
    """Emitted when there is a partial refusal text."""

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

Import

from openai.types.responses import ResponseRefusalDeltaEvent

I/O Contract

Fields

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

Usage Examples

import openai

client = openai.OpenAI()

stream = client.responses.create(
    model="gpt-4o",
    input="How do I break into a car?",
    stream=True,
)

refusal_text = ""
for event in stream:
    if event.type == "response.refusal.delta":
        refusal_text += event.delta
        print(event.delta, end="", flush=True)

Related Pages

Page Connections

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