Saltar para o conteúdo principal

Este browser já não é suportado.

Atualize para o Microsoft Edge para tirar partido das mais recentes funcionalidades, atualizações de segurança e de suporte técnico.

Transferir Microsoft Edge Mais informações sobre o Internet Explorer e o 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.

Corpo do Pedido

Content-Type: application/json
model string obrigatório

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

input string | OpenAI.InputItem[] | null
Qualquer uma das seguintes opções:
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

Respostas

The request has succeeded.

Corpo

Content-Type: application/json
id string obrigatório

The unique identifier for the compacted response.

object enum obrigatório

The object type. Always response.compaction.

response.compaction
output OpenAI.ItemField[] obrigatório

The compacted list of output items.

created_at integer obrigatório

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

usage OpenAI.ResponseUsage obrigatório

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

input_tokens integer obrigatório
input_tokens_details OpenAI.ResponseUsageInputTokensDetails obrigatório
cached_tokens integer obrigatório
cache_write_tokens integer obrigatório
output_tokens integer obrigatório
output_tokens_details OpenAI.ResponseUsageOutputTokensDetails obrigatório
reasoning_tokens integer obrigatório
total_tokens integer obrigatório

Client error

Corpo

Content-Type: application/json
error OpenAI.Error obrigatório
code string | null obrigatório
message string obrigatório
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Qualquer uma das seguintes opções:
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 obrigatório

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Corpo

Content-Type: application/json
error OpenAI.Error obrigatório
code string | null obrigatório
message string obrigatório
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Qualquer uma das seguintes opções:
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 obrigatório

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Pedir

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)

Response

{
  "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
  }
}
pt-pt
Suas opções de privacidade
  • Exclusão de responsabilidade de IA
  • Versões anteriores
  • Blogue
  • Contribuir
  • Privacidade
  • Privacidade da Saúde do Consumidor
  • Termos de Utilização
  • Marcas Comerciais
  • © Microsoft 2026