| page_title | openai_response Resource - terraform-provider-openai |
|---|---|
| subcategory | |
| description | Generates a response using the OpenAI Responses API. |
Generates a response using the OpenAI Responses API.
resource "openai_response" "full_example" {
model = "gpt-5.2"
input = "What is the weather in San Francisco?"
# Context
instructions = "You are a helpful assistant."
# conversation_id = "conv_12345" # Optional: To continue a conversation
# Tuning
top_p = 1.0
max_output_tokens = 100
truncation = "auto"
reasoning_effort = "medium"
# Metadata
metadata = {
"environment" = "test"
"user_id" = "user_123"
}
# Tools
tools = [
{
type = "function"
function = {
name = "get_weather"
description = "Get the current weather in a given location"
parameters = jsonencode({
type = "object"
properties = {
location = {
type = "string"
description = "The city and state, e.g. San Francisco, CA"
}
unit = {
type = "string"
enum = ["celsius", "fahrenheit"]
}
}
required = ["location"]
})
}
},
{
type = "web_search"
}
]
tool_choice = "auto"
parallel_tool_calls = true
# Output Format
response_format = "text" # or json_object, json_schema
include = ["web_search_call.action.sources"]
}
output "full_example_output" {
value = openai_response.full_example.content
}input(String) The input text for the response.model(String) The model to use for the response.
conversation_id(String) The unique ID of the conversation to initiate or continue.include(List of String) Specify additional output data to include in the model response. Currently supported values includeweb_search_call.action.sources,code_interpreter_call.outputs, etc.instructions(String) A system (or developer) message inserted into the model's context.max_output_tokens(Number) The maximum number of tokens to generate in the response.max_tool_calls(Number) The maximum number of tool calls to make in the response.metadata(Map of String) Set of 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.parallel_tool_calls(Boolean) Whether to allow parallel tool calls. Defaults to true.previous_response_id(String) The unique ID of the previous response to the model. Use this to create multi-turn conversations.prompt(Attributes) Reference to a prompt template and its variables. (see below for nested schema)reasoning_effort(String) Constrains effort on reasoning for reasoning models. Valid values arelow,medium,high.response_format(String) Specifies the format that the model must output. Compatible withjson_object,json_schema,text.temperature(Number) What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.tool_choice(String) Controls which (if any) tool is called by the model. Can benone,auto,required, or a specific function name.tools(Attributes List) A list of tools the model may call. Currently, only functions are supported as a tool. (see below for nested schema)top_logprobs(Number) An integer between 0 and 20 specifying the number of most likely tokens to return at each token position.top_p(Number) An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.truncation(String) Controls how the model truncates the context if it exceeds the maximum token limit. Valid values:auto,disabled.
content(String) The concatenated text content of the response. This is a convenience attribute for easy access to the generated text.created_at(Number) The Unix timestamp (in seconds) of when the response was created.id(String) The ID of the generated response.output(Attributes List) The generated output items. (see below for nested schema)
Required:
id(String) The unique ID of the prompt template to use.
Optional:
variables(String) JSON string of variables to pass to the prompt template.version(String) Optional version of the prompt template.
Required:
type(String) The type of the tool. Common values:function,web_search,file_search,computer_use,code_interpreter.
Optional:
function(Attributes) Function definition for the tool. (see below for nested schema)
Required:
name(String) The name of the function to be called.parameters(String) The parameters the functions accepts, described as a JSON Schema object.
Optional:
description(String) A description of what the function does, used by the model to choose when and how to call the function.
Read-Only:
content(String) The content of the output item. Currently only text content is extracted.type(String)