Implementation:Openai Openai python Response Compaction Item
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Responses_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete response type representing a compaction item returned by the Responses compact API, provided by the openai-python SDK.
Description
ResponseCompactionItem is a Pydantic model representing a compaction item generated by the v1/responses/compact API endpoint. It contains an id for the compaction item, encrypted_content holding the compacted data, a fixed type of "compaction", and an optional created_by field identifying the actor that created the item. This type is auto-generated from the OpenAI OpenAPI specification by Stainless.
Usage
Import ResponseCompactionItem when processing responses from the Responses compact API to work with compacted conversation data.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/response_compaction_item.py
Signature
class ResponseCompactionItem(BaseModel):
"""A compaction item generated by the v1/responses/compact API."""
id: str
encrypted_content: str
type: Literal["compaction"]
created_by: Optional[str] = None
Import
from openai.types.responses import ResponseCompactionItem
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| id | str |
Yes | The unique ID of the compaction item. |
| encrypted_content | str |
Yes | The encrypted content that was produced by compaction. |
| type | Literal["compaction"] |
Yes | The type of the item. Always "compaction".
|
| created_by | Optional[str] |
No | The identifier of the actor that created the item. |
Usage Examples
from openai.types.responses import ResponseCompactionItem
# After calling the compact endpoint
compacted = client.responses.compact(response_id="resp_abc123")
for item in compacted:
if isinstance(item, ResponseCompactionItem):
print(f"Compaction ID: {item.id}")
print(f"Encrypted content length: {len(item.encrypted_content)}")