Package com.sap.ai.sdk.foundationmodels.openai

# Class OpenAiChatCompletionResponse

java.lang.Object
com.sap.ai.sdk.foundationmodels.openai.OpenAiChatCompletionResponse

public final class OpenAiChatCompletionResponse extends Object
Represents the output of an OpenAI chat completion. *

Since:
  1.4.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object o)`
  `List<OpenAiToolMessage>`
  `executeTools()`
  Execute tool calls that were suggested by the assistant response.
  `CreateChatCompletionResponseChoicesInner`
  `getChoice()`
  Gets the first choice from the original response.
  `String`
  `getContent()`
  Gets the content of the first choice.
  `OpenAiAssistantMessage`
  `getMessage()`
  Gets the `OpenAiAssistantMessage` for the first choice.
  `CreateChatCompletionResponse`
  `getOriginalResponse()`
  The original response from the OpenAI API.
  `CompletionUsage`
  `getTokenUsage()`
  Gets the token usage from the original response.
  `int`
  `hashCode()`
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Method Details

  - ### getTokenUsage

    @Nonnull public CompletionUsage getTokenUsage()
    Gets the token usage from the original response.
    Returns:
      the token usage

  - ### getChoice

    @Nonnull public CreateChatCompletionResponseChoicesInner getChoice()
    Gets the first choice from the original response.
    Returns:
      the first choice

  - ### getContent

    @Nonnull public String getContent()
    Gets the content of the first choice.

    The content may be empty `""` if the assistant did not return any content i.e. when tool calls are present.

    Returns:
      the content of the first choice
    Throws:
      `OpenAiClientException` - if the content is filtered by the content filter

  - ### getMessage

    @Nonnull public OpenAiAssistantMessage getMessage()
    Gets the `OpenAiAssistantMessage` for the first choice.
    Returns:
      the assistant message
    Throws:
      `OpenAiClientException` - if the content is filtered by the content filter
    Since:
      1.6.0

  - ### executeTools

    @Nonnull public List<OpenAiToolMessage> executeTools()
    Execute tool calls that were suggested by the assistant response.
    Returns:
      the list of tool messages that were serialized for the computed results. Empty list if no tools were called.
    Since:
      1.8.0

  - ### getOriginalResponse

    @Nonnull public CreateChatCompletionResponse getOriginalResponse()
    The original response from the OpenAI API.

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`