OpenAI.Responses.Response (OpenAI.Responses v0.4.0)
View SourceRepresent a response from the OpenAI API.
The Response
struct contains the following fields:
text
: The extracted text from the response body.parsed
: The parsed response body.parse_error
: A map containing error messages if parsing failed.function_calls
: An array of extracted function calls from the response.body
: The raw response body.cost
: The calculated cost of the response in USD.
All of the functions in this module act like "plugs", meaning they take a response as input and return a modified response as output.
The extract_text/1
function extracts the text from the response body, updating the text
field of the response.
The extract_json/1
function extracts the data from the response body if it is a structured response.
The extract_function_calls/1
function extracts function calls from the response body.
The calculate_cost/1
function calculates the cost of the response based on token usage and model pricing.
Summary
Functions
Calculate the cost of the response based on token usage and model pricing.
Extract function calls from the response body.
Extract the data from the response body if it is a structured response.
Extract the text from the response body.
Functions
Calculate the cost of the response based on token usage and model pricing.
Returns the response with the cost
field updated with a map containing:
input_cost
: Cost for input tokens in USD (as Decimal)output_cost
: Cost for output tokens in USD (as Decimal)total_cost
: Total cost in USD (as Decimal)cached_discount
: Amount saved from cached tokens in USD (as Decimal) (if applicable)
If pricing information is not available for the model, or usage information is missing, the cost field will be set to nil.
Extract function calls from the response body.
Function calls are extracted from the response.body["output"] array and transformed into a more convenient format with parsed arguments.
Extract the data from the response body if it is a structured response.
Automatically extracts the text from the response body if it is not already extracted.
Extract the text from the response body.