We’re Heading to CNX ’25. Let's Meet in Chicago! Join HIC at Salesforce Connections'25 for conversations, collaboration, and co-creation.

The Models API plays a significant role in providing access to and facilitating interaction with large language models (LLMs) from various Salesforce partners such as Anthropic, Google, and OpenAI. It enables applications to leverage these models for various tasks, including text generation and other AI-powered capabilities.

As a user, you can configure any Salesforce-enabled model with Einstein Studio. If you want to customize model hyperparameters, create a custom-configured model in Einstein Studio and later use it with the Models API. 

Key Capabilities To Consider:

  1. Generate Chat
  2. Generate Embeddings
  3. Generate Text
  4. Submit Feedback

Steps to Generate Chat Using Model API

The Models API requires access to Einstein Generative AI on your Salesforce Org. If you don’t have an Org with this feature, you can get an Einstein AI Playground org from Trailhead to experiment or you can get a Developer Edition org with Agentforce and Data Cloud to experiment.

Step 1: Create a Salesforce Connected App

  • Log in to your newly created Salesforce org.
  • Go to the setup Button.
unnamed 24
  • Search for ‘Generative AI’ in the Quick Find box and select ‘Einstein Setup’
blogImg.1
  • After turning on Einstein, search for ‘App Manager’ in the Quick Find box, select ‘App Manager’, and click on ‘New Connected App’.
blogImg.2 1
  • Select “Create a Connected App” from the given two points mentioned below:
  1. Connected apps support plugins other than OAuth 2.0.
  2. ‘Create an External Client App’ supports only OAuth 2.0 plugins.
  •  Fill in the following details:
blogImg.3

Enable ‘OAuth settings’,
Fill ‘Callback URL’

  • Select the mentioned ‘OAuth Scopes’.
blogImg.4
blogImg.5
  • Click on the Save button, then continue.
  • A new Page will open, then click on the ‘Manage’ button.
m
  • Click on ‘Edit Policies’.
blogImg.7
  • Click on ‘Run as’, select the user you want to assign, check the appropriate checkbox, and save.
unnamed 32
  • After saving, you need to open the newly created Connected App from ‘App Manager’. Once the app is open, click on ‘Manage Consumer Details’.
unnamed 33
  • When you click on the ‘Manage Consumer Details’ button, you’ll be prompted to enter a verification code. Once it is done, you’ll be redirected to the Consumer Details Page, where you can find the Key and Secret.
blogImg.10

Step 2: Now go to Auth Providers and click on “New”

blogImg.11
  • Select ‘Provider Type’ as ‘Salesforce/Open id Connect’.
  • Fill in the Name (URL suffix will fill automatically), Consumer key, and consumer secret, and leave the rest. Then click on save.
s
  • Click on ‘Save’, and then copy the Callback URL provided.
unnamed 38
  • Now go back to your created App, and click on edit.
blogImg.14
  • And paste the URL in the Callback URL section and click on save.
blogImg.15

P.S. – You’ll get this message, just click continue. 

unnamed 41

Step 3: Set Up Named Credentials:

Now we have to create a Named Credential in Source ORG (In this example, in our org).

  • First, go to my domain and copy the Current My Domain URL and copy it.
blogImg.17
  • Now, go to the Named Credentials tab and click on the ‘New Legacy’ option.
blogImg.18
  • Fill in the details below (The URL will contain the Current My Domain URL that we copied and add “https://” before that), click on the little search icon before Authentication Provider, and click on save. Once you click on save.
blogImg.19
  • You’ll be redirected to the login page, log in to the target org, and click on Allow.
ss
  • Now that we’ve set up everything in our org, we can test it in Postman.

Step 4: Set Up in Postman

Now that we’ve set up everything in our org, we can have a demo in the Postman.

blogImg.20
  • Once you’ve created a fork, now it’s time to generate an authentication code.
  • Fill in Variable values after creating your workspace in Postman as mentioned below.

authDomain: Current My Domain URL( in My Domain)

clientId: Consumer Key from Connected App.

clientSecret: Consumer Secret from Connected App.

modelName: You can select any model Name from the given link( Supported Model).

_baseUrl: remain it as it is.

unnamed 49
  • Now, generate an authentication code if you want to test it directly in Postman. Inside ‘Authentication’ Click on the ‘ Get new Access Token’ button,  then ‘Proceed’, and then  ‘Use Token’.
blogImg.23
  • From the above Page inside the ‘Authentication’ tab, copy ‘Access Token URL’ and then paste it into ‘the Token Endpoint URL’ field of ‘Auth. Provider you created above, and enter the ‘Authorize Endpoint URL’ field value as mentioned below.

Authorize Endpoint URL: https://hostname/services/oauth2/authorize

Replace the hostname with My Domain URL(as mentioned in the below image).

blogImg.24
blogImg.25

Step 5: Development Work

  • Now you can go into any of the 4 sections of the Models API, we will explore all 4 options and what they do.

You can use the below chat based on your preference:

1. Generate text (standalone prompt)

In this, you will ask the chatbot only one question, and it will give you the answer based on that. 

blogImg.26

For example, we will ask “Tell me a developer Joke?” (Like why not, we are developers and we deserve a good developer joke)

blogImg.27

2. Generate chat (conversation with context)

In this, you will have a conversation with the chatbot, and the model will consider the previous chat and reply accordingly.

blogImg.28

As you can see, the chatbot has replied accordingly, but this is only 1 message and its reply, so what now? Now we can use the result it gave us and add our message.

blogImg.29

I have added the response from the assistant and gave my following message as well; now it will reply accordingly.

blogImg.30

3. Generate embeddings

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.

blogImg.31

Submit Feedback

This is based on the above text or chat, we can provide feedback if the chat is good or bad.

blogImg.32

We need to fill in the following details. In this example, we will provide the selected field and the ID from the above text.

blogImg.331 2

5.1 Create Apex class and Lightning component which uses the models API:

Now that we know how to use these models, we can create an intuitive UI to display the data.

For that, we need a lightning web component and an apex class.

  • Create Lightning Web Component (LWC). Open your Visual Studio Code and create a project, and in that:
unnamed 62
  • Create Apex Class in a similar way (Apex class name callModelAPIdata and Lwc name chatWindow).
  • Now copy the entire code.
  • LWC
  • CSS
  • JS
  • Apex code

Step 6: The Final Output

Now that we have put all the pieces together, we can finally see what it looks like.

unnamed 63
  • The green bubble represents the message sent to us, while the blue bubble represents the API’s response in a conversation format.
  • I have put this component on the Account record page, but you can put it on any page depending on your preference.

Demo Video

Related Articles
Expert Guide On Utilizing Agentforce for Seamless Quote & Case Creation

When it comes to managing customer journeys in Salesforce, speed and accuracy matter. That’s where Agentforce, a powerful extension layer, comes into play. Whether spinning up a new quote from an opportunity or logging a support case from a contact, Agentforce can help streamline these actions with minimal clicks and maximum context. In this blog, […]

Read More
How to Use Platform Events in Salesforce Flow for Real Time Updates

Platform events in Salesforce Flow are a great tool for creating real-time, event-driven apps that automate business operations with precision and speed. By integrating Platform Events’ publish-subscribe approach with Salesforce Flow‘s low-code features, you can automate processes, allow real-time system interaction, and optimize how your organization manages dynamic data changes. This guide will demonstrate how […]

Read More
Build a Dynamic Salesforce Data Viewer with hange kardo bas LWC

Lightning Web Components (LWC) is a modern JavaScript framework that is used for building responsive, dynamic applications on the Salesforce platform. In LWC, data flows from parent-to-child component. Variables marked as @api in the child component are open for a parent to pass values directly into the child’s HTML template, making the component interactable. To […]

Read More
Expert Guide On Nominal XIRR Calculation Using LWC in Salesforce

When building financial tools within Salesforce, handling irregular cash flows with precision is a must. Whether you’re developing investment trackers, portfolio performance dashboards, or funding monitors, calculating Nominal XIRR (Extended Internal Rate of Return) becomes essential. In this blog, you’ll learn how to build a Lightning Web Component (LWC) in Salesforce that calculates Nominal XIRR […]

Read More
Beginners Guide to Making Your LWC Component Multilingual

If you’re wondering how to make your LWC component multilingual, you’re already ahead of the curve. Global users expect content in their native language, and Salesforce gives you the tools to deliver exactly that. With Custom Labels and the Translation Workbench, you can easily localize your Lightning Web Components without touching a single line of […]

Read More
Hands-On Guide Building a Drag-and-Drop Form Builder Using Lightning Web Components

Drag-and-drop interfaces are a user experience staple, and when paired with the power of Lightning Web Components (LWC), they unlock dynamic, highly interactive Salesforce components. In this blog post, we’ll walk you through how to build a custom drag-and-drop form builder in LWC. Users can drag form fields like text inputs and dropdowns into a […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
6D - 7398 Yonge St #1124 Thornhill, ON L4J 8J2 Canada +1(262) 310-7818