Implementation:Openai Openai python Response Output Text Annotation Added
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Responses_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete type for representing an event emitted when an annotation is added to output text content during a streaming response, provided by the openai-python SDK.
Description
ResponseOutputTextAnnotationAddedEvent is a Pydantic model that represents the response.output_text.annotation.added streaming event. It is emitted when an annotation (such as a citation or file path) is appended to a text output content part. The event carries the annotation object itself, positional indices (annotation_index, content_index, output_index), the item_id of the parent output item, and a sequence_number for ordering within the event stream.
Usage
Import this type when you need to handle or type-check annotation-added events during streaming responses, for example when processing citations that appear in real time.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/response_output_text_annotation_added_event.py
Signature
class ResponseOutputTextAnnotationAddedEvent(BaseModel):
"""Emitted when an annotation is added to output text content."""
annotation: object
annotation_index: int
content_index: int
item_id: str
output_index: int
sequence_number: int
type: Literal["response.output_text.annotation.added"]
Import
from openai.types.responses import ResponseOutputTextAnnotationAddedEvent
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| annotation | object | Yes | The annotation object being added (see annotation schema for details). |
| annotation_index | int | Yes | The index of the annotation within the content part. |
| content_index | int | Yes | The index of the content part within the output item. |
| item_id | str | Yes | The unique identifier of the item to which the annotation is being added. |
| output_index | int | Yes | The index of the output item in the response's output array. |
| sequence_number | int | Yes | The sequence number of this event. |
| type | Literal["response.output_text.annotation.added"] | Yes | The type of the event. Always 'response.output_text.annotation.added'. |
Usage Examples
import openai
client = openai.OpenAI()
stream = client.responses.create(
model="gpt-4o",
input="Summarize recent AI news with citations.",
tools=[{"type": "web_search_preview"}],
stream=True,
)
for event in stream:
if event.type == "response.output_text.annotation.added":
print(f"Annotation added at index {event.annotation_index}: {event.annotation}")