Skip to content

Support compaction output type in Responses API (UnhandledMatchError in OutputObjects::parse) #777

@heyjones

Description

@heyjones

Version: v0.19.2

When context_management compaction is enabled on a Responses API request, the API returns an output item of type: "compaction". OutputObjects::parse() (src/Actions/Responses/OutputObjects.php) uses a match ($item['type']) with no arm for compaction and no default arm, so the entire response fails to parse with:

UnhandledMatchError: Unhandled match case 'compaction'

This is fatal — the whole response is unparseable, so even the message output in the same response is lost.

Reproduce

$client->responses()->create([
    'model' => 'gpt-5.4',
    'input' => $input,
    'conversation' => $conversationId,
    'context_management' => [
        ['type' => 'compaction', 'compact_threshold' => 50000],
    ],
]);
// throws once the conversation crosses the threshold and the API compacts

Request

Add handling for the compaction output item (e.g. an OutputCompaction response class + a 'compaction' => OutputCompaction::from($item) arm). At minimum, add a non-throwing default arm so an unrecognized output type doesn't make the entire response unparseable. Newer Responses API output types (context_management/compaction) are otherwise unusable with the client.

Environment

PHP 8.x, OpenAI Responses API, gpt-5.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions