Compact a response
BetaCompactedResponse beta().responses().compact(ResponseCompactParamsparams, RequestOptionsrequestOptions = RequestOptions.none())
POST/responses/compact
Compact a conversation. Returns a compacted response object.
Learn when and how to compact long-running conversations in the conversation state guide. For ZDR-compatible compaction details, see Compaction (advanced).
Compact a response
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.responses.BetaCompactedResponse;
import com.openai.models.beta.responses.ResponseCompactParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
ResponseCompactParams params = ResponseCompactParams.builder()
.model(ResponseCompactParams.Model.GPT_5_6_SOL)
.build();
BetaCompactedResponse betaCompactedResponse = client.beta().responses().compact(params);
}
}{
"id": "resp_001",
"object": "response.compaction",
"created_at": 1764967971,
"output": [
{
"id": "msg_000",
"type": "message",
"status": "completed",
"content": [
{
"type": "input_text",
"text": "Create a simple landing page for a dog petting cafe."
}
],
"role": "user"
},
{
"id": "cmp_001",
"type": "compaction",
"encrypted_content": "gAAAAABpM0Yj-...="
}
],
"usage": {
"input_tokens": 139,
"input_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0
},
"output_tokens": 438,
"output_tokens_details": {
"reasoning_tokens": 64
},
"total_tokens": 577
}
}
Returns Examples
{
"id": "resp_001",
"object": "response.compaction",
"created_at": 1764967971,
"output": [
{
"id": "msg_000",
"type": "message",
"status": "completed",
"content": [
{
"type": "input_text",
"text": "Create a simple landing page for a dog petting cafe."
}
],
"role": "user"
},
{
"id": "cmp_001",
"type": "compaction",
"encrypted_content": "gAAAAABpM0Yj-...="
}
],
"usage": {
"input_tokens": 139,
"input_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0
},
"output_tokens": 438,
"output_tokens_details": {
"reasoning_tokens": 64
},
"total_tokens": 577
}
}