Przejdź do głównej zawartości

Ta przeglądarka nie jest już obsługiwana.

Przejdź na przeglądarkę Microsoft Edge, aby korzystać z najnowszych funkcji, aktualizacji zabezpieczeń i pomocy technicznej.

Pobieranie przeglądarki Microsoft Edge Więcej informacji o przeglądarkach Internet Explorer i 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.

Treść żądania

Content-Type: application/json
model string wymagane

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

input string | OpenAI.InputItem[] | null
Którekolwiek z poniższych:
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

Odpowiedzi

The request has succeeded.

Treść

Content-Type: application/json
id string wymagane

The unique identifier for the compacted response.

object enum wymagane

The object type. Always response.compaction.

response.compaction
output OpenAI.ItemField[] wymagane

The compacted list of output items.

created_at integer wymagane

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

usage OpenAI.ResponseUsage wymagane

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

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

Client error

Treść

Content-Type: application/json
error OpenAI.Error wymagane
code string | null wymagane
message string wymagane
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Którekolwiek z poniższych:
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 wymagane

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Treść

Content-Type: application/json
error OpenAI.Error wymagane
code string | null wymagane
message string wymagane
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Którekolwiek z poniższych:
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 wymagane

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Żądanie

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
  }
}
pl-pl
Wybrane przez Ciebie opcje dotyczące prywatności
  • Zastrzeżenie dotyczące sztucznej inteligencji
  • Poprzednie wersje
  • Blog
  • Współtworzenie
  • Prywatność
  • Prywatność kondycji konsumenta
  • Warunki użytkowania
  • Znaki towarowe
  • © Microsoft 2026