Responses
Cancel a model response
Cancels a model response with the given ID. Only responses created with the background parameter set to true can be cancelled.
Parâmetros de caminho
response_id
string
obrigatório
The ID of the response to cancel.
Parâmetros do cabeçalho
x-ms-user-identity
string
Opaque per-user identity string used to scope endpoint-scoped data to a specific end user. The caller must have the agents/endpoints/UserIdentityImpersonation/action RBAC permission.
Respostas
The request has succeeded.
Cabeçalhos
x-agent-session-id
string
Session ID for this request. Only present for hosted agent responses. Returns the provided session ID or an auto-generated one if not provided in the request.
Corpo
metadata
OpenAI.Metadata | null
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
user
string | null
This field is being replaced by safety_identifier and prompt_cache_key. Use prompt_cache_key instead to maintain caching optimizations. A stable identifier for your end-users. Used to boost cache hit rates by better bucketing similar requests and to help OpenAI detect and prevent abuse. Learn more.
prompt_cache_retention
enum
model
string
The model deployment to use for the creation of this response.
text
OpenAI.ResponseTextParam
Configuration options for a text response from the model. Can be plain text or structured JSON data. Learn more: - Text inputs and outputs - Structured Outputs
format
json_schema | text | json_object
An object specifying the format that the model must output. Configuring { "type": "json_schema" } enables Structured Outputs, which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide. The default format is { "type": "text" } with no additional options. Not recommended for gpt-4o and newer models:* Setting to { "type": "json_object" } enables the older JSON mode, which ensures the message the model generates is valid JSON. Using json_schema is preferred for models that support it.
json_schema
OpenAI.TextResponseFormatJsonSchema
JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.
type
enum
obrigatório
The type of response format being defined. Always json_schema.
description
string
A description of what the response format is for, used by the model to determine how to respond in the format.
name
string
obrigatório
The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
schema
OpenAI.ResponseFormatJsonSchemaSchema
obrigatório
The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas here.
text
OpenAI.TextResponseFormatConfigurationResponseFormatText
Default response format. Used to generate text responses.
type
enum
obrigatório
The type of response format being defined. Always text.
json_object
OpenAI.TextResponseFormatConfigurationResponseFormatJsonObject
JSON object response format. An older method of generating JSON responses. Using json_schema is recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.
type
enum
obrigatório
The type of response format being defined. Always json_object.
verbosity
enum
Constrains the verbosity of the model's response. Lower values will result in more concise responses, while higher values will result in more verbose responses. Currently supported values are low, medium, and high. The default is medium.
tools
OpenAI.Tool[]
An array of tools the model may call while generating a response. You can specify which tool to use by setting the tool_choice parameter. We support the following categories of tools: - Built-in tools: Tools that are provided by OpenAI that extend the model's capabilities, like web search or file search. Learn more about built-in tools. - MCP Tools: Integrations with third-party systems via custom MCP servers or predefined connectors such as Google Drive and SharePoint. Learn more about MCP Tools. - Function calls (custom tools): Functions that are defined by you, enabling the model to call your own code with strongly typed arguments and outputs. Learn more about function calling. You can also use custom tools to call your own code.
tool_choice
enum | OpenAI.ToolChoiceParam
enum
Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools.
function
OpenAI.ToolChoiceFunction
Use this option to force the model to call a specific function.
type
enum
obrigatório
For function calling, the type is always function.
name
string
obrigatório
The name of the function to call.
mcp
OpenAI.ToolChoiceMCP
Use this option to force the model to call a specific tool on a remote MCP server.
type
enum
obrigatório
For MCP tools, the type is always mcp.
server_label
string
obrigatório
The label of the MCP server to use.
allowed_tools
OpenAI.ToolChoiceAllowed
Constrains the tools available to the model to a pre-defined set.
type
enum
obrigatório
Allowed tool configuration type. Always allowed_tools.
mode
enum
obrigatório
Constrains the tools available to the model to a pre-defined set. auto allows the model to pick from among the allowed tools and generate a message. required requires the model to call one or more of the allowed tools.
tools
object[]
obrigatório
A list of tool definitions that the model should be allowed to call. For the Responses API, the list of tool definitions might look like: json [ { "type": "function", "name": "get_weather" }, { "type": "mcp", "server_label": "deepwiki" }, { "type": "image_generation" } ]
custom
OpenAI.ToolChoiceCustom
Use this option to force the model to call a specific custom tool.
type
enum
obrigatório
For custom tool calling, the type is always custom.
name
string
obrigatório
The name of the custom tool to call.
programmatic_tool_calling
OpenAI.SpecificProgrammaticToolCallingParam
type
enum
obrigatório
The tool to call. Always programmatic_tool_calling.
apply_patch
OpenAI.SpecificApplyPatchParam
Forces the model to call the apply_patch tool when executing a tool call.
type
enum
obrigatório
The tool to call. Always apply_patch.
shell
OpenAI.SpecificFunctionShellParam
Forces the model to call the shell tool when a tool call is required.
type
enum
obrigatório
The tool to call. Always shell.
file_search
OpenAI.ToolChoiceFileSearch
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
web_search_preview
OpenAI.ToolChoiceWebSearchPreview
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
computer_use_preview
OpenAI.ToolChoiceComputerUsePreview
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
web_search_preview_2025_03_11
OpenAI.ToolChoiceWebSearchPreview20250311
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
image_generation
OpenAI.ToolChoiceImageGeneration
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
code_interpreter
OpenAI.ToolChoiceCodeInterpreter
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
computer
OpenAI.ToolChoiceComputer
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
computer_use
OpenAI.ToolChoiceComputerUse
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
type
enum
obrigatório
prompt
OpenAI.Prompt
Reference to a prompt template and its variables. Learn more.
id
string
obrigatório
The unique identifier of the prompt template to use.
variables
OpenAI.ResponsePromptVariables | null
Optional map of values to substitute in for variables in your prompt. The substitution values can either be strings, or other Response input types like images or files.
[key: string]
string | OpenAI.InputTextContent | OpenAI.InputImageContent | OpenAI.InputFileContent
type
enum
obrigatório
The type of the input item. Always input_text.
text
string
obrigatório
The text input to the model.
prompt_cache_breakpoint
OpenAI.PromptCacheBreakpointConfig
Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL from the request's prompt_cache_options.ttl; the boundary is not rounded to a token block.
mode
enum
obrigatório
The breakpoint mode. Always explicit.
type
enum
obrigatório
The type of the input item. Always input_image.
detail
enum
obrigatório
prompt_cache_breakpoint
OpenAI.PromptCacheBreakpointConfig
Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL from the request's prompt_cache_options.ttl; the boundary is not rounded to a token block.
mode
enum
obrigatório
The breakpoint mode. Always explicit.
type
enum
obrigatório
The type of the input item. Always input_file.
filename
string
The name of the file to be sent to the model.
file_data
string
The content of the file to be sent to the model.
prompt_cache_breakpoint
OpenAI.PromptCacheBreakpointConfig
Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL from the request's prompt_cache_options.ttl; the boundary is not rounded to a token block.
mode
enum
obrigatório
The breakpoint mode. Always explicit.
file_url
string
The URL of the file to be sent to the model.
detail
enum
service_tier
enum
Specifies the processing type used for serving the request. - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'. - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model. - If set to 'flex', then the request will be processed with the Flex Processing service tier. - To opt-in to Fast mode at the request level, include the service_tier=fast or service_tier=priority parameter for Responses or Chat Completions. The response will show service_tier=priority regardless of if you specify service_tier=fast or priority in your request. - If set to 'ultrafast', then the request will be processed with the access-controlled Ultrafast Processing service tier. This tier is currently available for gpt-5.6-sol; a response served through it will show service_tier=ultrafast. - When not set, the default behavior is 'auto'. When the service_tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
truncation
enum
id
string
obrigatório
Unique identifier for this Response.
object
enum
obrigatório
The object type of this resource - always set to response.
status
enum
The status of the response generation. One of completed, failed, in_progress, cancelled, queued, or incomplete.
access_programs
OpenAI.AccessProgramsBody | null
obrigatório
cyber
enum
obrigatório
created_at
integer
obrigatório
Unix timestamp (in seconds) of when this Response was created.
error
OpenAI.ResponseError | null
obrigatório
An error object returned when the model fails to generate a Response.
type
string | null
The original error type, or null if it was not recorded.
param
string | null
The request parameter associated with the error, or null if none was recorded.
code
enum
obrigatório
The error code for the response.
message
string
obrigatório
A human-readable description of the error.
misalignment
OpenAI.MisalignmentErrorDetailsResource
error_type
string | enum
enum
detailed_explanation
string
The public explanation for this block.
steer
OpenAI._MisalignmentSteer
message
string
obrigatório
The public continuation instruction.
incomplete_details
OpenAI.ResponseIncompleteDetails | null
obrigatório
reason
enum
output
OpenAI.OutputItem[]
obrigatório
An array of content items generated by the model. - The length and order of items in the output array is dependent on the model's response. - Rather than accessing the first item in the output array and assuming it's an assistant message with the content generated by the model, you might consider using the output_text property where supported in SDKs.
reasoning
OpenAI.Reasoning | null
Configuration options for reasoning models.
mode
string | enum
enum
effort
string | enum | null
Constrains effort on reasoning for reasoning models. Currently supported values are none, minimal, low, medium, high, xhigh, and max. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response. Not all reasoning models support every value. See the reasoning guide for model-specific support.
enum
summary
enum
context
enum
generate_summary
enum
instructions
string | OpenAI.InputItem[] | null
obrigatório
usage
OpenAI.ResponseUsage | null
Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used.
input_tokens_details
OpenAI.ResponseUsageInputTokensDetails
obrigatório
output_tokens_details
OpenAI.ResponseUsageOutputTokensDetails
obrigatório
prompt_cache_options
OpenAI.PromptCacheOptions
The prompt-caching options that were applied to the response. Supported for gpt-5.6 and later models.
ttl
enum
obrigatório
mode
enum
obrigatório
prompt_cache_diagnostics
cache_miss | cache_hit | comparison_response_not_found | unavailable
Prompt cache diagnostics requested for this response.
cache_miss
OpenAI.PromptCacheMissDiagnosticsBody
type
enum
obrigatório
reason
enum
obrigatório
cache_hit
OpenAI.PromptCacheHitDiagnosticsBody
type
enum
obrigatório
comparison_response_not_found
OpenAI.PromptCacheComparisonResponseNotFoundDiagnosticsBody
type
enum
obrigatório
unavailable
OpenAI.PromptCacheUnavailableDiagnosticsBody
type
enum
obrigatório
moderation
OpenAI.Moderation | null
Moderation results or errors for the response input and output.
input
error | moderation_result
obrigatório
Moderation results or an error for a response moderation check.
error
OpenAI.ModerationErrorBody
An error produced while attempting moderation for the response input or output.
type
enum
obrigatório
The object type, which was always error for moderation failures.
code
string
obrigatório
The error code.
message
string
obrigatório
The error message.
moderation_result
OpenAI.ModerationResultBody
A moderation result produced for the response input or output.
type
enum
obrigatório
The object type, which was always moderation_result for successful moderation results.
model
string
obrigatório
The moderation model that produced this result.
flagged
boolean
obrigatório
A boolean indicating whether the content was flagged by any category.
categories
object
obrigatório
A dictionary of moderation categories to booleans, True if the input is flagged under this category.
category_scores
object
obrigatório
A dictionary of moderation categories to scores.
category_applied_input_types
object
obrigatório
Which modalities of input are reflected by the score for each category.
output
error | moderation_result
obrigatório
Moderation results or an error for a response moderation check.
error
OpenAI.ModerationErrorBody
An error produced while attempting moderation for the response input or output.
type
enum
obrigatório
The object type, which was always error for moderation failures.
code
string
obrigatório
The error code.
message
string
obrigatório
The error message.
moderation_result
OpenAI.ModerationResultBody
A moderation result produced for the response input or output.
type
enum
obrigatório
The object type, which was always moderation_result for successful moderation results.
model
string
obrigatório
The moderation model that produced this result.
flagged
boolean
obrigatório
A boolean indicating whether the content was flagged by any category.
categories
object
obrigatório
A dictionary of moderation categories to booleans, True if the input is flagged under this category.
category_scores
object
obrigatório
A dictionary of moderation categories to scores.
category_applied_input_types
object
obrigatório
Which modalities of input are reflected by the score for each category.
parallel_tool_calls
boolean
obrigatório
Whether to allow the model to run tool calls in parallel.
conversation
OpenAI.ResponseConversation | null
The conversation that this response belonged to. Input items and output items from this response were automatically added to this conversation.
id
string
obrigatório
The unique ID of the conversation that this response was associated with.
agent_reference
AgentReference | null
obrigatório
The agent used for this response
type
enum
obrigatório
name
string
obrigatório
The name of the agent.
version
string
The version identifier of the agent.
model_selection_details
ModelSelectionDetails
Model selection metadata providing visibility into routing decisions.
model_router_details
ModelRouterDetails
obrigatório
Routing decision metadata from Model Router.
mode
string | enum
obrigatório
The routing mode used by Model Router for the request.
enum
session_affinity
SessionAffinityDetails
Effective Model Router session affinity metadata for a request.
mode
string | enum
obrigatório
Effective modes reported for Model Router session affinity.
enum
source
string | enum
Conversation identifier sources supported by Model Router session affinity.
enum
decision
string | enum
Final outcomes reported for Model Router session affinity.
enum
routing_trace
RoutingTraceEntry[]
obrigatório
Ordered trace of routing decisions. Contains one entry for Chat Completions, and may contain multiple entries for Responses API or agent scenarios where multiple inference turns occur.
content_filters
ContentFilterResult[]
The content filter evaluation results.
Pedir
curl -X POST https://api.openai.com/v1/responses/resp_123/cancel \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY"
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.cancel("resp_123");
console.log(response);
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
response = client.responses.cancel(
"resp_677efb5139a88190b512bc3fef8e535d",
)
print(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 response = await client.responses.cancel('resp_677efb5139a88190b512bc3fef8e535d');
console.log(response.id);
package main
import (
"context"
"fmt"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Responses.Cancel(context.TODO(), "resp_677efb5139a88190b512bc3fef8e535d")
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", response.ID)
}
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCancelParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
Response response = client.responses().cancel("resp_677efb5139a88190b512bc3fef8e535d");
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
response = openai.responses.cancel("resp_677efb5139a88190b512bc3fef8e535d")
puts(response)
Response
{
"id": "resp_67cb71b351908190a308f3859487620d06981a8637e6bc44",
"object": "response",
"created_at": 1741386163,
"status": "cancelled",
"background": true,
"completed_at": null,
"error": null,
"incomplete_details": null,
"instructions": null,
"max_output_tokens": null,
"model": "gpt-4o-2024-08-06",
"output": [
{
"type": "message",
"id": "msg_67cb71b3c2b0819084d481baaaf148f206981a8637e6bc44",
"status": "in_progress",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Silent circuits hum,
Thoughts emerge in data streams—
Digital dawn breaks.",
"annotations": []
}
]
}
],
"parallel_tool_calls": true,
"previous_response_id": null,
"reasoning": {
"effort": null,
"summary": null
},
"store": true,
"temperature": 1.0,
"text": {
"format": {
"type": "text"
}
},
"tool_choice": "auto",
"tools": [],
"top_p": 1.0,
"truncation": "disabled",
"usage": null,
"user": null,
"metadata": {}
}