Skip to content

feat(OpenAI): add the compact endpoint of the Responses API - #845

Open
skybleak333 wants to merge 1 commit into
openai-php:mainfrom
skybleak333:feat/responses-compact
Open

skybleak333 wants to merge 1 commit into
openai-php:mainfrom
skybleak333:feat/responses-compact

Conversation

@skybleak333

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description:

Adds POST /v1/responses/compact, which compacts a conversation: the user messages stay as they are and everything else becomes one encrypted compaction item, to send as the input of the next request instead of the whole history (compaction guide).

$response = $client->responses()->compact([
    'model' => 'gpt-5.1-codex-max',
    'previous_response_id' => 'resp_67ccd2bed1ec8190b14f964abc054267',
]);

$response->object; // 'response.compaction'
$response->output;  // [InputMessage, ..., OutputCompaction]
$response->usage->totalTokens;

CompactedResponse parses output with ItemObjects, not OutputObjects. The official SDKs type it as output items, but the user messages come back as input messages, {"type": "message", "role": "user", "content": [{"type": "input_text", ...}]} (see the response example in Azure's Compact a conversation reference), and OutputMessage only knows output_text and refusal content. The optional image field of the response is not mapped.

With a fake fixture from that example, compact() on ResponsesTestResource, and a README section. The full suite, Pint and PHPStan pass.

This and #844 both add a method to ResponsesContract and tests next to each other, so whichever is merged second will need a rebase; I'll do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant