Models API Apex Classes (Beta)

This feature is a Beta Service. Customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.

The Models API provides Apex classes that connect your application to large language models (LLMs). To get started, see Access Models API with Apex.

This page lists all the Apex classes that are autogenerated from the Models REST API specification using External Services. The methods for each capability are located within the main ModelsAPI class. The rest of the classes contain property values associated with a request or a response.

The namespace for all Models API classes is aiplatform.

The main class for the Models API.

The methods of the ModelsAPI class are the primary way to interact with the Models API via Apex.

Generate a response based on a list of messages representing a chat conversation.

Create an embedding vector representing the input text.

Generate a response based on the provided prompt.

Submit feedback for generated text.

The child classes of the ModelsAPI parent class.

Contains the request information for a chat generations request.

PropertyTypeDescription
modelNameStringConfigured model name. To learn more, see Supported Models for Models API.
bodyModelsAPI_ChatGenerationsRequestGeneration request class containing the messages, localization, and necessary tags.

Contains the response information for a chat generations response.

PropertyTypeDescription
Code200ModelsAPI_ChatGenerationsResponseThe response information for a successful chat generations response, including the prompt and generated text.
responseCodeIntegerAn HTTP status code.

An exception for chat generation responses other than Code200. For information on HTTP and status code standards, see RFC 9110 HTTP Semantics.

PropertyTypeDescription
responseCodeIntegerAn HTTP status code.
Code400ModelsAPI_ErrorAn HTTP code 400 error response.
Code401ModelsAPI_ErrorAn HTTP code 401 error response.
Code403ModelsAPI_ErrorAn HTTP code 403 error response.
Code423ModelsAPI_ErrorAn HTTP code 423 error response.
Code429ModelsAPI_ErrorAn HTTP code 429 error response.
Code500ModelsAPI_ErrorAn HTTP code 500 error response.
Code503ModelsAPI_ErrorAn HTTP code 503 error response.
defaultResponseModelsAPI_ErrorA default error response.

Contains the request information for a generations request.

PropertyTypeDescription
modelNameStringConfigured model name. To learn more, see Supported Models for Models API.
bodyModelsAPI_GenerationRequestGeneration request class containing the prompt, localization, and necessary tags.

Contains the response information for a generations response.

PropertyTypeDescription
Code200ModelsAPI_GenerationResponseThe response information for a successful chat generations response, including the prompt and generated text.
responseCodeIntegerResponse code.

An exception for generation responses other than Code200. For information on HTTP and status code standards, see RFC 9110 HTTP Semantics.

PropertyTypeDescription
responseCodeIntegerAn HTTP status code.
Code400ModelsAPI_ErrorAn HTTP code 400 error response.
Code401ModelsAPI_ErrorAn HTTP code 401 error response.
Code403ModelsAPI_ErrorAn HTTP code 403 error response.
Code423ModelsAPI_ErrorAn HTTP code 423 error response.
Code429ModelsAPI_ErrorAn HTTP code 429 error response.
Code500ModelsAPI_ErrorAn HTTP code 500 error response.
Code503ModelsAPI_ErrorAn HTTP code 503 error response.
defaultResponseModelsAPI_ErrorA default error response.

Contains the request information for an embeddings request.

PropertyTypeDescription
modelNameStringConfigured model name. To learn more, see Supported Models for Models API.
bodyModelsAPI_EmbeddingRequestEmbedding class containing input text, localization, and necessary tags.

Contains the response information for an embeddings request.

PropertyTypeDescription
Code200ModelsAPI_EmbeddingResponseThe response information for a successful embedding response.
responseCodeIntegerAn HTTP status code.

An exception for embeddings responses other than Code200. For information on HTTP and status code standards, see RFC 9110 HTTP Semantics.

PropertyTypeDescription
responseCodeIntegerAn HTTP status code.
Code400ModelsAPI_ErrorAn HTTP code 400 error response.
Code401ModelsAPI_ErrorAn HTTP code 401 error response.
Code403ModelsAPI_ErrorAn HTTP code 403 error response.
Code423ModelsAPI_ErrorAn HTTP code 423 error response.
Code429ModelsAPI_ErrorAn HTTP code 429 error response.
Code500ModelsAPI_ErrorAn HTTP code 500 error response.
Code503ModelsAPI_ErrorAn HTTP code 503 error response.
defaultResponseModelsAPI_ErrorA default error response.

Contains the request information for a feedback submission.

PropertyTypeDescription
bodyModelsAPI_FeedbackRequestRequest body.

The response information for an accepted feedback response.

PropertyTypeDescription
Code202ModelsAPI_submitFeedback_OUT_202The response information for an accepted feedback response.
responseCodeIntegerAn HTTP status code.

An exception for chat feedback responses other than Code200. For information on HTTP and status code standards, see RFC 9110 HTTP Semantics.

PropertyTypeDescription
responseCodeIntegerAn HTTP status code.
Code400ModelsAPI_ErrorAn HTTP code 400 error response.
Code401ModelsAPI_ErrorAn HTTP code 401 error response.
Code403ModelsAPI_ErrorAn HTTP code 403 error response.
Code423ModelsAPI_ErrorAn HTTP code 423 error response.
Code429ModelsAPI_ErrorAn HTTP code 429 error response.
Code500ModelsAPI_ErrorAn HTTP code 500 error response.
Code503ModelsAPI_ErrorAn HTTP code 503 error response.
defaultResponseModelsAPI_ErrorA default error response.

A chat generation request.

PropertyTypeDescription
messagesList<ModelsAPI_ChatMessageRequest>List of messages to send to the model. These messages should be in chronological order.
localizationModelsAPI_LocalizationLocalization information, which can include the default locale, input locale(s), and expected output locale(s).
tagsModelsAPI_TagsEntries used by the Models API for non-generative purposes and entries used by the client for free-form data.

A chat generation response.

PropertyTypeDescription
idStringUnique identifier for the response.
generationDetailsModelsAPI_GenerationDetailsDetails for a chat generation response.

A message in a conversation. This message is used in a chat generation response.

PropertyTypeDescription
idStringGeneration ID. Required to register feedback.
roleStringPersona that sent the message.
contentStringThe content of the message.
timestampLongTimestamp when the message was sent.
parametersModelsAPI_ChatMessage_parametersProvider-specific attributes included as part of this object.
contentQualityModelsAPI_ContentTrustRepresentationContent quality details.

A message in a conversation. This message is used in a chat generation request.

PropertyTypeDescription
roleStringPersona that sent the message.
contentStringThe content of the message.

Any provider-specific attributes included as part of this object.

PropertyTypeDescription
propertiesMap of String, ObjectProvider-specific properties.

This class is deprecated.

Content moderation details for generated content.

PropertyTypeDescription
scanToxicityModelsAPI_TrustScannerRepresentationToxicity scan details.

An embedding request.

PropertyTypeDescription
inputList<String>Input text used for generating an embedding. Data is encoded as an array of strings.
localizationModelsAPI_LocalizationLocalization information, which can include the default locale, input locale(s), and expected output locale(s).
tagsModelsAPI_TagsEntries used by the Models API for non-generative purposes and entries used by the client for free-form data.

An embedding response.

PropertyTypeDescription
embeddingsList<ModelsAPI_Embeddings>A list of embedding responses.
parametersModelsAPI_EmbeddingResponse_parametersAny provider-specific attributes included as part of this object.

Any provider-specific attributes included as part of this object.

PropertyTypeDescription
propertiesMap of String, ObjectProvider-specific properties.

An embedding vector for the text.

PropertyTypeDescription
embeddingList<Double>Embedding of the text. Data is specified as an array of numbers.
indexIntegerIndex of the input text to which the embedding belongs.

Models API error.

PropertyTypeDescription
errorCodeStringError code to map the error message.
messageCodeStringA specification of the error that uniquely identifies an error message.
messageStringDescription of the error.
targetsList<ModelsAPI_Error_targets>Collection of references representing the specific occurrence of the problem.
parametersList<ModelsAPI_Error_parameters>A collection of name-value pairs where each item in the collection represents a parameter leveraged in the error message.
propertiesMap of String, ObjectA map of the properties.

A collection of name-value pairs where each item in the collection represents a parameter leveraged in the error message.

PropertyTypeDescription
nameStringParameter name.
valueStringParameter value.

Collection of references representing the specific occurrence of the problem.

PropertyTypeDescription
z0typeStringType of the target (FIELD, QUERY_PARAMETER, HTTP_HEADER).
referenceStringReference to the specific occurrence of the problem.

A feedback request.

PropertyTypeDescription
idStringUnique ID for the feedback object.
generationIdStringIdentifies the target of this feedback data. You can specify the ID of a /generations response, or use any other identifier as a string value. The Models API doesn’t do any semantic validation on this field. It’s only meant for identifying this information in the datastore.
feedbackStringThe feedback sentiment. Can be null.
feedbackTextStringThe textual representation of the feedback as provided by the user.
sourceStringThe source of the feedback. For example, human or app.
appFeedbackModelsAPI_FeedbackRequest_appFeedbackDictionary of any app-level feedback and any other free-form parameters.
appGenerationIdStringApp-specific generation ID to support cases where the client has multiple responses in a single generation.
appGenerationStringApp-specific generation text to support cases where the client has multiple responses in a single generation.

Dictionary of any app-level feedback and any other free-form parameters.

PropertyTypeDescription
propertiesMap of String, ObjectA map of the properties.

Details for a chat generation response.

PropertyTypeDescription
generationsList<ModelsAPI_ChatMessage>A list of messages used in a chat generation response.
parametersModelsAPI_GenerationDetails_parametersAny provider-specific attributes included as part of this object.

Any provider-specific attributes included as part of this object.

PropertyTypeDescription
propertiesMap of String, ObjectA map of the properties.

The generated text that is part of the generation response.

PropertyTypeDescription
idStringGeneration ID. This value is required to register feedback.
generatedTextStringThe generated text.
contentQualityModelsAPI_ContentTrustRepresentationContent moderation details for generated content.
parametersModelsAPI_GenerationRepresentation_parametersAny provider-specific attributes included as part of this object. Can be null.

Any provider-specific attributes included as part of this object. Can be null.

PropertyTypeDescription
propertiesMap of String, ObjectA map of the properties.

A generation request containing prompt, localization, and tag information.

PropertyTypeDescription
promptStringThe prompt or text to be completed.
localizationModelsAPI_LocalizationLocalization information, which can include the default locale, input locale(s), and expected output locale(s).
tagsModelsAPI_TagsEntries used by the Models API for non-generative purposes and entries used by the client for free-form data.

A generations response.

PropertyTypeDescription
idStringID of the generation request.
generationModelsAPI_GenerationRepresentationThe generated text that is part of the generation response.
moreGenerationsList<ModelsAPI_GenerationRepresentation>List of generated text items if the number of requested generations is greater than one.
promptStringPrompt used for the generation. Can be null.
parametersModelsAPI_GenerationResponse_parametersAny provider-specific attributes included as part of this object. Can be null.

Any provider-specific attributes included as part of this object. Can be null.

PropertyTypeDescription
propertiesMap of String, ObjectA map of the properties.

Localization information, which can include the default locale, input locale(s), and expected output locale(s). To learn more, see Specify Languages and Locales with Models API.

PropertyTypeDescription
defaultLocaleStringDefault locale.
inputLocalesList<ModelsAPI_ProbableLocale>List of language codes or locales found in the prompt.
expectedLocalesList<String>Expected output languages of the generations. Derived from the output language instructions of the prompt.

The locale and an optional probability value.

PropertyTypeDescription
localeStringA language or locale.
probabilityDoubleAn estimate of how frequently you expect this language or locale to appear in the input.

Entries used by the Models API for non-generative purposes and entries used by the client for free-form data.

PropertyTypeDescription
propertiesMap of String, ObjectA map of the properties.

Safety score for a given category.

PropertyTypeDescription
categoryNameStringName of the category.
scoreDoubleA toxicity score value. A higher score means the response is more likely to be toxic.

Represents safety and toxicity data.

PropertyTypeDescription
isDetectedBooleanIndicates whether a scan detected any toxic content. A false value doesn’t necessarily mean that the content isn’t toxic.
categoriesList<ModelsAPI_TrustCategoryDetail>List of safety scores for different categories.

An accepted feedback message.

PropertyTypeDescription
messageStringAn accepted feedback message.