Models API Developer Guide

The Models API provides Apex classes and REST endpoints that connect your application to large language models (LLMs) from Salesforce partners, including Anthropic, Google, and OpenAI. You can use any Salesforce-enabled model that can be configured in Einstein Studio.

For a list of API names and other details about specific models, see Supported Models for Models API.

All calls to the Models API go through the Einstein Trust Layer.

The capabilities of the Models API are expressed as Apex methods or REST endpoints, depending on which version of the API you choose.

The Models API can generate a message for a chat conversation. The chat capability allows you to prompt the model with a list of messages rather than just one prompt (providing only one message is fine too). Each message in the list represents a part of a conversation history. You must specify a role for each message: one of user, system, or assistant. The role helps the model understand the conversation and know how to respond. After you pass in this information, the API responds with generated text.

An embedding is a numerical representation of a chunk of content. Sometimes an embedding is called an embedding vector. To measure the semantic similarity between two chunks of content, you can use mathematical operations on their embedding vectors, such as cosine similarity, Euclidean distance, or dot product. Embeddings are commonly used for retrieval-augmented generation (RAG) and semantic search features.

The Models API can generate text from a single prompt instead of a whole chat conversation. The generate text capability is useful for simple, non-conversational tasks and for testing the capabilities of a model.

You can provide feedback on any generated text created by the Models API. You can use this data, which is stored in Data Cloud, to review the quality of the responses and then update your requests or your model configurations. See Einstein Audit and Feedback Data in Salesforce Help.

To learn how to use the Models API to unlock these capabilities, see our Apex and REST access guides. The Apex classes are great for developing solutions directly in your org. You can also use the Apex classes to build out Lightning web components. The REST API can be used from your existing implementation wherever it resides.