Implementation:Openai Openai python Response Output Text
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Responses_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete type for representing text output content from the model along with citation annotations and log probabilities, provided by the openai-python SDK.
Description
ResponseOutputText is a Pydantic model representing a text output from the model. It contains the text content, a list of annotations (citations and file paths), and an optional logprobs field with token-level log probabilities. The type field is always "output_text".
The module also defines several supporting types:
- Annotation - A discriminated union TypeAlias of citation types: AnnotationFileCitation (file citations with file_id, filename, index), AnnotationURLCitation (web citations with start_index, end_index, title, url), AnnotationContainerFileCitation (container file citations with container_id, file_id, filename, start_index, end_index), and AnnotationFilePath (file paths with file_id, index).
- Logprob - Token log probability with token, bytes, logprob, and top_logprobs fields.
- LogprobTopLogprob - A top log probability candidate for a given token position.
Usage
Import this type when you need to inspect the text content, citations, or log probabilities within output message content items from the Responses API.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/response_output_text.py
Signature
class ResponseOutputText(BaseModel):
"""A text output from the model."""
annotations: List[Annotation]
text: str
type: Literal["output_text"]
logprobs: Optional[List[Logprob]] = None
Import
from openai.types.responses import ResponseOutputText
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| annotations | List[Annotation] | Yes | The annotations of the text output (citations, file paths). |
| text | str | Yes | The text output from the model. |
| type | Literal["output_text"] | Yes | The type of the output text. Always output_text.
|
| logprobs | Optional[List[Logprob]] | No | Token-level log probabilities, if requested. |
Annotation Union Members
| Type | Discriminator Value | Key Fields |
|---|---|---|
| AnnotationFileCitation | "file_citation" | file_id, filename, index |
| AnnotationURLCitation | "url_citation" | start_index, end_index, title, url |
| AnnotationContainerFileCitation | "container_file_citation" | container_id, file_id, filename, start_index, end_index |
| AnnotationFilePath | "file_path" | file_id, index |
Logprob Fields
| Name | Type | Description |
|---|---|---|
| token | str | The token string. |
| bytes | List[int] | The byte representation of the token. |
| logprob | float | The log probability of the token. |
| top_logprobs | List[LogprobTopLogprob] | The top log probability candidates. |
Usage Examples
import openai
client = openai.OpenAI()
response = client.responses.create(
model="gpt-4o",
input="What is the capital of France?",
tools=[{"type": "web_search_preview"}],
)
for item in response.output:
if item.type == "message":
for content in item.content:
if content.type == "output_text":
print(content.text)
# Inspect annotations (citations)
for annotation in content.annotations:
if annotation.type == "url_citation":
print(f" Citation: {annotation.title} - {annotation.url}")
elif annotation.type == "file_citation":
print(f" File: {annotation.filename} ({annotation.file_id})")