OpenAIResponseFormat

sealed interface OpenAIResponseFormat

Specifies the format that the model must output.

  • Text is the default response format used to generate text responses.

  • JsonObject enables the legacy JSON mode which ensures the generated message is valid JSON. Note that the model still needs a system or user message instructing it to produce JSON.

  • JsonSchema enables Structured Outputs which ensures the model matches the supplied JSON Schema. Prefer JsonSchema over JsonObject for models that support it.

See also

Samples

val request = openAIChatCompletionRequest(model = "gpt-5.6-sol") {
    responseFormat = OpenAIResponseFormat.JsonObject

    messages(messages)
}

Inheritors

Types

Link copied to clipboard

Legacy JSON object response format ({"type": "json_object"}).

Link copied to clipboard
data class JsonSchema(val name: String, val description: String? = null, val schema: JsonObject? = null, val strict: Boolean? = null) : OpenAIResponseFormat

Structured JSON Schema response format.

Link copied to clipboard

Default text response format ({"type": "text"}).