Ir al contenido principal

Este explorador ya no se admite.

Actualice a Microsoft Edge para aprovechar las características y actualizaciones de seguridad más recientes, y disponer de soporte técnico.

Descargar Microsoft Edge Más información sobre Internet Explorer y Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Responses

Compact a conversation

POST /openai/v1/responses/compact

Compacts a conversation into a response object suitable for long-running and zero-data-retention scenarios.

Cuerpo de la solicitud

Content-Type: application/json
model string requerido

The model deployment to use for the compaction of this response.

input string | OpenAI.InputItem[] | null
Cualquiera de las siguientes:
string
OpenAI.InputItem[]
previous_response_id string | null
instructions string | null
prompt_cache_key string | null
prompt_cache_retention enum
in_memory24h
prompt_cache_options OpenAI.PromptCacheOptionsParam | null

Options for prompt caching. Supported for gpt-5.6 and later models. By default, OpenAI automatically chooses one implicit cache breakpoint. You can add explicit breakpoints to content blocks with prompt_cache_breakpoint. Each request can write up to four breakpoints. For cache matching, OpenAI considers up to the latest 80 breakpoints in the conversation, without a content-block lookback limit. Set mode to explicit to disable the implicit breakpoint. The ttl defaults to 30m, which is currently the only supported value. See the prompt caching guide for current details.

ttl enum
30m
mode enum
implicitexplicit
service_tier enum
autodefaultfastflexpriority

Respuestas

The request has succeeded.

Cuerpo

Content-Type: application/json
id string requerido

The unique identifier for the compacted response.

object enum requerido

The object type. Always response.compaction.

response.compaction
output OpenAI.ItemField[] requerido

The compacted list of output items.

created_at integer requerido

Unix timestamp (in seconds) when the compacted conversation was created.

usage OpenAI.ResponseUsage requerido

Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used.

input_tokens integer requerido
input_tokens_details OpenAI.ResponseUsageInputTokensDetails requerido
cached_tokens integer requerido
cache_write_tokens integer requerido
output_tokens integer requerido
output_tokens_details OpenAI.ResponseUsageOutputTokensDetails requerido
reasoning_tokens integer requerido
total_tokens integer requerido

Client error

Cuerpo

Content-Type: application/json
error OpenAI.Error requerido
code string | null requerido
message string requerido
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Cualquiera de las siguientes:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string requerido

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Cuerpo

Content-Type: application/json
error OpenAI.Error requerido
code string | null requerido
message string requerido
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Cualquiera de las siguientes:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string requerido

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Solicitar

curl -X POST https://api.openai.com/v1/responses/compact \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
      "model": "gpt-5.1-codex-max",
      "input": [
        {
          "role": "user",
          "content": "Create a simple landing page for a dog petting café."
        },
        {
          "id": "msg_001",
          "type": "message",
          "status": "completed",
          "content": [
            {
              "type": "output_text",
              "annotations": [],
              "logprobs": [],
              "text": "Below is a single file, ready-to-use landing page for a dog petting café:..."
            }
          ],
          "role": "assistant"
        }
      ]
    }'
import OpenAI from "openai";

const openai = new OpenAI();

// Compact the previous response if you are running out of tokens
const compactedResponse = await openai.responses.compact({
  model: "gpt-5.1-codex-max",
  input: [
    {
      role: "user",
      content: "Create a simple landing page for a dog petting café.",
    },
    // All items returned from previous requests are included here, like reasoning, message, function call, etc.
    {
      id: "msg_030d085c0b53e67e0069332e3a72d4819c96c6f2c4adc15d33",
      type: "message",
      status: "completed",
      content: [
        {
          type: "output_text",
          annotations: [],
          logprobs: [],
          text: "Below is a single file, ready-to-use landing page for a dog petting café:...",
        },
      ],
      role: "assistant",
    },
  ],
});

// Pass the compactedResponse.output as input to the next request
console.log(compactedResponse);
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
compacted_response = client.responses.compact(
    model="gpt-5.4",
)
print(compacted_response.id)
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

const compactedResponse = await client.responses.compact({ model: 'gpt-5.4' });

console.log(compactedResponse.id);
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
    "github.com/openai/openai-go/responses"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    compactedResponse, err := client.Responses.Compact(context.TODO(), responses.ResponseCompactParams{
        Model: responses.ResponseCompactParamsModelGPT5_4,
    })
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", compactedResponse.ID)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.CompactedResponse;
import com.openai.models.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_4)
            .build();
        CompactedResponse compactedResponse = client.responses().compact(params);
    }
}
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

compacted_response = openai.responses.compact(model: :"gpt-5.4")

puts(compacted_response)

Respuesta

{
  "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
    },
    "output_tokens": 438,
    "output_tokens_details": {
      "reasoning_tokens": 64
    },
    "total_tokens": 577
  }
}
es-es
Sus opciones de privacidad
  • Declinación de responsabilidades de IA
  • Versiones anteriores
  • Blog
  • Contribuir
  • Privacidad
  • Privacidad de estado del consumidor
  • Términos de uso
  • Marcas comerciales
  • © Microsoft 2026