# mirascope.core.openai.call_response
## <ApiType type="Module" path="core/openai/call_response" symbolName="call_response" /> call_response
This module contains the `OpenAICallResponse` class.
<Info title="Usage">
[Calls](/docs/v1/learn/calls#handling-responses)
</Info>
## <ApiType type="Class" path="core/openai/call_response" symbolName="ChatCompletionAudio" /> ChatCompletionAudio
<AttributesTable
attributes={[
{
"name": "data",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
}
},
{
"name": "transcript",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
}
}
]}
/>
## <ApiType type="Class" path="core/openai/call_response" symbolName="OpenAICallResponse" /> OpenAICallResponse
A convenience wrapper around the OpenAI `ChatCompletion` response.
When calling the OpenAI API using a function decorated with `openai_call`, the
response will be an `OpenAICallResponse` instance with properties that allow for
more convenience access to commonly used attributes.
Example:
```python
from mirascope.core import prompt_template
from mirascope.core.openai import openai_call
@openai_call("gpt-4o")
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"
response = recommend_book("fantasy") # response is an `OpenAICallResponse` instance
print(response.content)
```
**Bases:**
<TypeLink type={{"type_str": "BaseCallResponse[ChatCompletion, OpenAITool, ChatCompletionToolParam, OpenAIDynamicConfig, ChatCompletionMessageParam, OpenAICallParams, ChatCompletionUserMessageParam, OpenAIMessageParamConverter]", "description": null, "kind": "generic", "base_type": {"type_str": "BaseCallResponse", "description": null, "kind": "simple", "doc_url": "/docs/v1/api/core/base/call_response#basecallresponse"}, "parameters": [{"type_str": "ChatCompletion", "description": null, "kind": "simple", "doc_identifier": "ChatCompletion"}, {"type_str": "OpenAITool", "description": null, "kind": "simple", "doc_url": "/docs/v1/api/core/openai/tool#openaitool"}, {"type_str": "ChatCompletionToolParam", "description": null, "kind": "simple", "doc_identifier": "ChatCompletionToolParam"}, {"type_str": "OpenAIDynamicConfig", "description": null, "kind": "simple", "doc_url": "/docs/v1/api/core/openai/dynamic_config#openaidynamicconfig"}, {"type_str": "ChatCompletionMessageParam", "description": null, "kind": "simple", "doc_identifier": "ChatCompletionMessageParam"}, {"type_str": "OpenAICallParams", "description": null, "kind": "simple", "doc_url": "/docs/v1/api/core/openai/call_params#openaicallparams"}, {"type_str": "ChatCompletionUserMessageParam", "description": null, "kind": "simple", "doc_identifier": "ChatCompletionUserMessageParam"}, {"type_str": "OpenAIMessageParamConverter", "description": null, "kind": "simple", "doc_identifier": "OpenAIMessageParamConverter"}]}} />
<AttributesTable
attributes={[
{
"name": "response",
"type_info": {
"type_str": "SkipValidation[ChatCompletion]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "SkipValidation",
"description": null,
"kind": "simple",
"doc_url": "https://docs.pydantic.dev/latest/api/functional_validators/#pydantic.functional_validators.SkipValidation"
},
"parameters": [
{
"type_str": "ChatCompletion",
"description": null,
"kind": "simple",
"doc_identifier": "ChatCompletion"
}
]
}
},
{
"name": "content",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
},
"description": "Returns the content of the chat completion for the 0th choice."
},
{
"name": "finish_reasons",
"type_info": {
"type_str": "list[str]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "list",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#list"
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
}
]
},
"description": "Returns the finish reasons of the response."
},
{
"name": "model",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
},
"description": "Returns the name of the response model."
},
{
"name": "id",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
},
"description": "Returns the id of the response."
},
{
"name": "usage",
"type_info": {
"type_str": "CompletionUsage | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "CompletionUsage",
"description": null,
"kind": "simple",
"doc_identifier": "CompletionUsage"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the usage of the chat completion."
},
{
"name": "input_tokens",
"type_info": {
"type_str": "int | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "int",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/functions.html#int"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the number of input tokens."
},
{
"name": "cached_tokens",
"type_info": {
"type_str": "int | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "int",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/functions.html#int"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the number of cached tokens."
},
{
"name": "output_tokens",
"type_info": {
"type_str": "int | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "int",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/functions.html#int"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the number of output tokens."
},
{
"name": "message_param",
"type_info": {
"type_str": "SerializeAsAny[ChatCompletionAssistantMessageParam]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "SerializeAsAny",
"description": null,
"kind": "simple",
"doc_identifier": "SerializeAsAny"
},
"parameters": [
{
"type_str": "ChatCompletionAssistantMessageParam",
"description": null,
"kind": "simple",
"doc_identifier": "ChatCompletionAssistantMessageParam"
}
]
},
"description": "Returns the assistants's response as a message parameter."
},
{
"name": "tools",
"type_info": {
"type_str": "list[OpenAITool] | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "list[OpenAITool]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "list",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#list"
},
"parameters": [
{
"type_str": "OpenAITool",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/openai/tool#openaitool"
}
]
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns any available tool calls as their `OpenAITool` definition."
},
{
"name": "tool",
"type_info": {
"type_str": "OpenAITool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "OpenAITool",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/openai/tool#openaitool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the 0th tool for the 0th choice message."
},
{
"name": "audio",
"type_info": {
"type_str": "bytes | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bytes",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#bytes"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the audio data of the response."
},
{
"name": "audio_transcript",
"type_info": {
"type_str": "str | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Returns the transcript of the audio content."
},
{
"name": "common_finish_reasons",
"type_info": {
"type_str": "list[FinishReason] | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "list[FinishReason]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "list",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#list"
},
"parameters": [
{
"type_str": "FinishReason",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/openai/call_response_chunk#finishreason"
}
]
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
},
"description": "Provider-agnostic finish reasons."
},
{
"name": "common_message_param",
"type_info": {
"type_str": "BaseMessageParam",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/base/message_param#basemessageparam"
}
},
{
"name": "common_user_message_param",
"type_info": {
"type_str": "BaseMessageParam | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "BaseMessageParam",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/base/message_param#basemessageparam"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
]
}
},
{
"name": "cost_metadata",
"type_info": {
"type_str": "CostMetadata",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/base/types#costmetadata"
}
}
]}
/>
## <ApiType type="Function" path="core/openai/call_response" symbolName="tool_message_params" /> tool_message_params
Returns the tool message parameters for tool call results.
<ParametersTable
parameters={[
{
"name": "cls",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"doc_identifier": null
}
},
{
"name": "tools_and_outputs",
"type_info": {
"type_str": "Sequence[tuple[OpenAITool, str]]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Sequence",
"description": null,
"kind": "simple",
"doc_identifier": "Sequence"
},
"parameters": [
{
"type_str": "tuple[OpenAITool, str]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "tuple",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#tuple"
},
"parameters": [
{
"type_str": "OpenAITool",
"description": null,
"kind": "simple",
"doc_url": "/docs/v1/api/core/openai/tool#openaitool"
},
{
"type_str": "str",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#str"
}
]
}
]
},
"description": "The sequence of tools and their outputs from which the tool\nmessage parameters should be constructed."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "list[ChatCompletionToolMessageParam]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "list",
"description": null,
"kind": "simple",
"doc_url": "https://docs.python.org/3/library/stdtypes.html#list"
},
"parameters": [
{
"type_str": "ChatCompletionToolMessageParam",
"description": null,
"kind": "simple",
"doc_identifier": "ChatCompletionToolMessageParam"
}
]
},
"description": "The list of constructed `ChatCompletionToolMessageParam` parameters."
}}
/>