Access Models API with REST
The Models REST API connects your application to large language models (LLMs) for chat, embeddings, text generation, and feedback.
Before you make a request, complete the shared authentication flow to create a Salesforce app and generate a JSON Web Token (JWT). See Authenticate to the Models API. Then use your token to call the endpoints described here.
All Models API requests are subject to Salesforce’s usage and billing rates for Einstein Requests. See Agentforce and Generative AI Usage and Billing and the Rate Card for Einstein Requests.
The quickest way to get started with the Models REST API is with our Postman collection.
When you have a valid token, you can call any of the Models REST API endpoints.
The Models REST API provides four different endpoints for four different capabilities.
| Capability | Endpoint Path | Description |
|---|---|---|
| Generate Chat | /models/{modelName}/chat-generations | Generate a response based on a list of messages representing a chat conversation. |
| Generate Embeddings | /models/{modelName}/embeddings | Create an embedding vector representing the input text. |
| Generate Text | /models/{modelName}/generations | Generate a response based on the prompt provided. |
| Submit Feedback | /feedback | Submit feedback for generated text. |
Choose a model to use when you call the generations or embeddings endpoints. Each endpoint, other than the feedback endpoint, requires the API name of the model as part of the path. For instance, if you want to use the OpenAI GPT-4o mini model for a generation request, specify the API name sfdc_ai__DefaultOpenAIGPT4OmniMini by making a request to this endpoint.
The Models API supports models from various Salesforce-enabled providers. See Supported Models.
These headers are relevant for API requests.
| Header | Description | Example |
|---|---|---|
Authorization | Required. Authorization method for this request. This header must contain your JWT. | Bearer {token} |
Content-Type | Required. Specify the application/json content type. | application/json |
x-sfdc-app-context | Required. This value is reserved for future use. For now, specify EinsteinGPT. | EinsteinGPT |
x-client-feature-id | Required. This value is reserved for future use. For now, specify ai-platform-models-connected-app. | ai-platform-models-connected-app |
Make a POST request to one of the Models REST API endpoints. This example demonstrates a call to the generations endpoint.
If you receive a 401 or 404 response code, verify that your Salesforce app includes all the required scopes and settings, and that you’re using the complete access_token value that you generated. See Authenticate to the Models API.
And here’s a sample response.
After you successfully call the API, refer to these topics to optimize your implementation.
- Supported Models
- Rate Limits for Models API
- Specify Languages and Locales with Models API
- Toxicity Scoring with Models API
- Data Masking with Models API
- Get Generation Feedback Using Models API
- Access Models API with Apex
- Build Lightning Web Components and Flows with Models API
- Models REST API Reference
- Salesforce Help: Agentforce and Einstein Generative AI
- Salesforce Help: External Client Apps