ResponseFormat class sealed

Specifies the format that the model must output.

Compatible with GPT-4o, GPT-4o mini, GPT-4 Turbo, and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106.

Example

// Request JSON output
final request = ChatCompletionCreateRequest(
  model: 'gpt-4o',
  messages: [...],
  responseFormat: ResponseFormat.jsonObject(),
);

// Request specific JSON schema
final request = ChatCompletionCreateRequest(
  model: 'gpt-4o',
  messages: [...],
  responseFormat: ResponseFormat.jsonSchema(
    name: 'person',
    schema: {
      'type': 'object',
      'properties': {
        'name': {'type': 'string'},
        'age': {'type': 'integer'},
      },
      'required': ['name', 'age'],
    },
  ),
);
Implementers
Annotations
  • @immutable

Constructors

ResponseFormat.fromJson(Map<String, dynamic> json)
Creates a ResponseFormat from JSON.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type String
The type identifier for this format.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts to JSON.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

jsonObject() ResponseFormat
Creates a JSON object response format.
jsonSchema({required String name, required Map<String, dynamic> schema, String? description, bool strict = true}) ResponseFormat
Creates a JSON schema response format.
text() ResponseFormat
Creates a text response format.