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
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
Please Make Blog Banner How to Create an Agentforce Enabled Scratch Org in Salesforce 100 1

Setting up an Agentforce-enabled scratch org is the most important step for developers who want to experiment with AI features such as Prompt Builder and Einstein GPT. Whether you’re developing the next generation CRM software or experimenting with how generative AI may improve user experience, a scratch org equipped with Agentforce is your playground. Follow […]

Read More
Step-by-Step Guide to Enhance Your LWC Development Workflow with the Logger API

Are you looking to streamline your LWC development workflow but confused about how to do it? Then you are in the right place. The Salesforce Logger API is a powerful tool that helps you monitor, debug, and improve code quality in real time.  This step-by-step guide walks you through how to set it up and […]

Read More
Enhancing Your Salesforce Experience with a Custom Activity Component

In today’s fast-paced business landscape, productivity hinges on streamlined workflows and intuitive interfaces. While Salesforce offers robust activity tracking capabilities, sometimes the standard components fall short of specific organizational needs.  That’s where a Custom Activity Component comes in—designed to tailor your activity management experience, boost user efficiency, and provide deeper insights into customer interactions. In […]

Read More
Step-by-Step Guide to Integrating Salesforce Doc-Gen with eSigning Tools

In today’s fast-paced digital landscape, streamlining document workflows is no longer a luxury—it’s a necessity.  Integrating a document generation app, like Docs Made Easy, with an eSigning tool, helps businesses automate the entire document lifecycle—from creation to signature—saving time, reducing errors, and boosting productivity. In this guide, we’ll walk you through the key steps, tools, […]

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
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818