Models API Apex Classes
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.
- Parameters: createChatGenerations_Request input
- Returns: createChatGenerations_Response
- Throws: createChatGenerations_ResponseException
- Signature:
createChatGenerations_Response createChatGenerations(createChatGenerations_Request input);
- Example:
aiplatform.ModelsAPI.createChatGenerations_Response response = modelsAPI.createChatGenerations(request);
Create an embedding vector representing the input text.
- Parameters: createEmbeddings_Request input
- Returns: createEmbeddings_Response
- Throws: createEmbeddings_ResponseException
- Signature:
createEmbeddings_Response createEmbeddings(createEmbeddings_Request input)
- Example:
aiplatform.ModelsAPI.createEmbeddings_Request request = new aiplatform.ModelsAPI.createEmbeddings_Request();
Generate a response based on the provided prompt.
- Parameters: createGenerations_Request input
- Returns: createGenerations_Response
- Throws: createGenerations_ResponseException
- Signature:
createChatGenerations_Response createChatGenerations(createChatGenerations_Request input);
- Example:
aiplatform.ModelsAPI.createChatGenerations_Response response = modelsAPI.createChatGenerations(request);
Submit feedback for generated text.
- Parameters: submitFeedback_Request input
- Returns: submitFeedback_Response
- Throws: submitFeedback_ResponseException
- Signature:
submitFeedback_Response submitFeedback(submitFeedback_Request input)
- Example:
aiplatform.ModelsAPI.submitFeedback_Response response = modelsAPI.submitFeedback(request);
The child classes of the ModelsAPI
parent class.
Contains the request information for a chat generations request.
Property | Type | Description |
---|---|---|
modelName | String | Configured model name. To learn more, see Supported Models for Models API. |
body | ModelsAPI_ChatGenerationsRequest | Generation request class containing the messages, localization, and necessary tags. |
Contains the response information for a chat generations response.
Property | Type | Description |
---|---|---|
Code200 | ModelsAPI_ChatGenerationsResponse | The response information for a successful chat generations response, including the prompt and generated text. |
responseCode | Integer | An 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.
Property | Type | Description |
---|---|---|
responseCode | Integer | An HTTP status code. |
Code400 | ModelsAPI_Error | An HTTP code 400 error response. |
Code401 | ModelsAPI_Error | An HTTP code 401 error response. |
Code403 | ModelsAPI_Error | An HTTP code 403 error response. |
Code423 | ModelsAPI_Error | An HTTP code 423 error response. |
Code429 | ModelsAPI_Error | An HTTP code 429 error response. |
Code500 | ModelsAPI_Error | An HTTP code 500 error response. |
Code503 | ModelsAPI_Error | An HTTP code 503 error response. |
defaultResponse | ModelsAPI_Error | A default error response. |
Contains the request information for a generations request.
Property | Type | Description |
---|---|---|
modelName | String | Configured model name. To learn more, see Supported Models for Models API. |
body | ModelsAPI_GenerationRequest | Generation request class containing the prompt, localization, and necessary tags. |
Contains the response information for a generations response.
Property | Type | Description |
---|---|---|
Code200 | ModelsAPI_GenerationResponse | The response information for a successful chat generations response, including the prompt and generated text. |
responseCode | Integer | Response code. |
An exception for generation responses other than Code200
. For information on HTTP and status code standards, see RFC 9110 HTTP Semantics.
Property | Type | Description |
---|---|---|
responseCode | Integer | An HTTP status code. |
Code400 | ModelsAPI_Error | An HTTP code 400 error response. |
Code401 | ModelsAPI_Error | An HTTP code 401 error response. |
Code403 | ModelsAPI_Error | An HTTP code 403 error response. |
Code423 | ModelsAPI_Error | An HTTP code 423 error response. |
Code429 | ModelsAPI_Error | An HTTP code 429 error response. |
Code500 | ModelsAPI_Error | An HTTP code 500 error response. |
Code503 | ModelsAPI_Error | An HTTP code 503 error response. |
defaultResponse | ModelsAPI_Error | A default error response. |
Contains the request information for an embeddings request.
Property | Type | Description |
---|---|---|
modelName | String | Configured model name. To learn more, see Supported Models for Models API. |
body | ModelsAPI_EmbeddingRequest | Embedding class containing input text, localization, and necessary tags. |
Contains the response information for an embeddings request.
Property | Type | Description |
---|---|---|
Code200 | ModelsAPI_EmbeddingResponse | The response information for a successful embedding response. |
responseCode | Integer | An HTTP status code. |
An exception for embeddings responses other than Code200
. For information on HTTP and status code standards, see RFC 9110 HTTP Semantics.
Property | Type | Description |
---|---|---|
responseCode | Integer | An HTTP status code. |
Code400 | ModelsAPI_Error | An HTTP code 400 error response. |
Code401 | ModelsAPI_Error | An HTTP code 401 error response. |
Code403 | ModelsAPI_Error | An HTTP code 403 error response. |
Code423 | ModelsAPI_Error | An HTTP code 423 error response. |
Code429 | ModelsAPI_Error | An HTTP code 429 error response. |
Code500 | ModelsAPI_Error | An HTTP code 500 error response. |
Code503 | ModelsAPI_Error | An HTTP code 503 error response. |
defaultResponse | ModelsAPI_Error | A default error response. |
Contains the request information for a feedback submission.
Property | Type | Description |
---|---|---|
body | ModelsAPI_FeedbackRequest | Request body. |
The response information for an accepted feedback response.
Property | Type | Description |
---|---|---|
Code202 | ModelsAPI_submitFeedback_OUT_202 | The response information for an accepted feedback response. |
responseCode | Integer | An 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.
Property | Type | Description |
---|---|---|
responseCode | Integer | An HTTP status code. |
Code400 | ModelsAPI_Error | An HTTP code 400 error response. |
Code401 | ModelsAPI_Error | An HTTP code 401 error response. |
Code403 | ModelsAPI_Error | An HTTP code 403 error response. |
Code423 | ModelsAPI_Error | An HTTP code 423 error response. |
Code429 | ModelsAPI_Error | An HTTP code 429 error response. |
Code500 | ModelsAPI_Error | An HTTP code 500 error response. |
Code503 | ModelsAPI_Error | An HTTP code 503 error response. |
defaultResponse | ModelsAPI_Error | A default error response. |
A chat generation request.
Property | Type | Description |
---|---|---|
messages | List<ModelsAPI_ChatMessageRequest> | List of messages to send to the model. These messages should be in chronological order. |
localization | ModelsAPI_Localization | Localization information, which can include the default locale, input locale(s), and expected output locale(s). |
tags | ModelsAPI_Tags | Entries used by the Models API for non-generative purposes and entries used by the client for free-form data. |
A chat generation response.
Property | Type | Description |
---|---|---|
id | String | Unique identifier for the response. |
generationDetails | ModelsAPI_GenerationDetails | Details for a chat generation response. |
A message in a conversation. This message is used in a chat generation response.
Property | Type | Description |
---|---|---|
id | String | Generation ID. Required to register feedback. |
role | String | Persona that sent the message. |
content | String | The content of the message. |
timestamp | Long | Timestamp when the message was sent. |
parameters | ModelsAPI_ChatMessage_parameters | Provider-specific attributes included as part of this object. |
contentQuality | ModelsAPI_ContentTrustRepresentation | Content quality details. |
A message in a conversation. This message is used in a chat generation request.
Property | Type | Description |
---|---|---|
role | String | Persona that sent the message. |
content | String | The content of the message. |
Any provider-specific attributes included as part of this object.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | Provider-specific properties. |
This class is deprecated.
Content moderation details for generated content.
Property | Type | Description |
---|---|---|
scanToxicity | ModelsAPI_TrustScannerRepresentation | Toxicity scan details. |
An embedding request.
Property | Type | Description |
---|---|---|
input | List<String> | Input text used for generating an embedding. Data is encoded as an array of strings. |
localization | ModelsAPI_Localization | Localization information, which can include the default locale, input locale(s), and expected output locale(s). |
tags | ModelsAPI_Tags | Entries used by the Models API for non-generative purposes and entries used by the client for free-form data. |
An embedding response.
Property | Type | Description |
---|---|---|
embeddings | List<ModelsAPI_Embeddings> | A list of embedding responses. |
parameters | ModelsAPI_EmbeddingResponse_parameters | Any provider-specific attributes included as part of this object. |
Any provider-specific attributes included as part of this object.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | Provider-specific properties. |
An embedding vector for the text.
Property | Type | Description |
---|---|---|
embedding | List<Double> | Embedding of the text. Data is specified as an array of numbers. |
index | Integer | Index of the input text to which the embedding belongs. |
Models API error.
Property | Type | Description |
---|---|---|
errorCode | String | Error code to map the error message. |
messageCode | String | A specification of the error that uniquely identifies an error message. |
message | String | Description of the error. |
targets | List<ModelsAPI_Error_targets> | Collection of references representing the specific occurrence of the problem. |
parameters | List<ModelsAPI_Error_parameters> | A collection of name-value pairs where each item in the collection represents a parameter leveraged in the error message. |
properties | Map of String, Object | A map of the properties. |
A collection of name-value pairs where each item in the collection represents a parameter leveraged in the error message.
Property | Type | Description |
---|---|---|
name | String | Parameter name. |
value | String | Parameter value. |
Collection of references representing the specific occurrence of the problem.
Property | Type | Description |
---|---|---|
z0type | String | Type of the target (FIELD, QUERY_PARAMETER, HTTP_HEADER). |
reference | String | Reference to the specific occurrence of the problem. |
A feedback request.
Property | Type | Description |
---|---|---|
id | String | Unique ID for the feedback object. |
generationId | String | Identifies 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. |
feedback | String | The feedback sentiment. Can be null . |
feedbackText | String | The textual representation of the feedback as provided by the user. |
source | String | The source of the feedback. For example, human or app . |
appFeedback | ModelsAPI_FeedbackRequest_appFeedback | Dictionary of any app-level feedback and any other free-form parameters. |
appGenerationId | String | App-specific generation ID to support cases where the client has multiple responses in a single generation. |
appGeneration | String | App-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.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | A map of the properties. |
Details for a chat generation response.
Property | Type | Description |
---|---|---|
generations | List<ModelsAPI_ChatMessage> | A list of messages used in a chat generation response. |
parameters | ModelsAPI_GenerationDetails_parameters | Any provider-specific attributes included as part of this object. |
Any provider-specific attributes included as part of this object.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | A map of the properties. |
The generated text that is part of the generation response.
Property | Type | Description |
---|---|---|
id | String | Generation ID. This value is required to register feedback. |
generatedText | String | The generated text. |
contentQuality | ModelsAPI_ContentTrustRepresentation | Content moderation details for generated content. |
parameters | ModelsAPI_GenerationRepresentation_parameters | Any 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
.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | A map of the properties. |
A generation request containing prompt, localization, and tag information.
Property | Type | Description |
---|---|---|
prompt | String | The prompt or text to be completed. |
localization | ModelsAPI_Localization | Localization information, which can include the default locale, input locale(s), and expected output locale(s). |
tags | ModelsAPI_Tags | Entries used by the Models API for non-generative purposes and entries used by the client for free-form data. |
A generations response.
Property | Type | Description |
---|---|---|
id | String | ID of the generation request. |
generation | ModelsAPI_GenerationRepresentation | The generated text that is part of the generation response. |
moreGenerations | List<ModelsAPI_GenerationRepresentation> | List of generated text items if the number of requested generations is greater than one. |
prompt | String | Prompt used for the generation. Can be null. |
parameters | ModelsAPI_GenerationResponse_parameters | Any 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
.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | A 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.
Property | Type | Description |
---|---|---|
defaultLocale | String | Default locale. |
inputLocales | List<ModelsAPI_ProbableLocale> | List of language codes or locales found in the prompt. |
expectedLocales | List<String> | Expected output languages of the generations. Derived from the output language instructions of the prompt. |
The locale and an optional probability value.
Property | Type | Description |
---|---|---|
locale | String | A language or locale. |
probability | Double | An 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.
Property | Type | Description |
---|---|---|
properties | Map of String, Object | A map of the properties. |
Safety score for a given category.
Property | Type | Description |
---|---|---|
categoryName | String | Name of the category. |
score | Double | A toxicity score value. A higher score means the response is more likely to be toxic. |
Represents safety and toxicity data.
Property | Type | Description |
---|---|---|
isDetected | Boolean | Indicates whether a scan detected any toxic content. A false value doesn’t necessarily mean that the content isn’t toxic. |
categories | List<ModelsAPI_TrustCategoryDetail> | List of safety scores for different categories. |
An accepted feedback message.
Property | Type | Description |
---|---|---|
message | String | An accepted feedback message. |