---
schema_version: "1"
id: 9c6ec072ca6ab8be83dd8f3bb84a09bc94096dfea8cbfa29bc53b69c782f3200
title: Access Models API with REST
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/genai/agentforce/guides/models/models-api/access-models-api-with-rest.md
canonical_url: https://developer.salesforce.com/docs/ai/agentforce/guide/access-models-api-with-rest.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d99435f3355224f354ff40d689b537dca9d30bbd72d4479beea91e0be65b4313
products:
  - Agentforce Developer Guide
  - Agentforce and Einstein Generative AI
---
# 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](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-authentication.md). Then use your token to call the endpoints described here.

**note:** All Models API requests are subject to Salesforce’s usage and billing rates for Einstein Requests. See [Agentforce and Generative AI Usage and Billing](https://help.salesforce.com/s/articleView?id=ai.generative_ai_usage.htm) and the [Rate Card for Einstein Requests](https://www.salesforce.com/products/einstein/skus/).

## Postman Collection

The quickest way to get started with the Models REST API is with our [Postman collection](https://www.postman.com/salesforce-developers/workspace/salesforce-developers/collection/12721794-582bb775-b99d-46d8-88cf-df0d3a341040).

## Call the Models REST API

When you have a valid token, you can call any of the Models REST API endpoints.

### Pick a Capability

The Models REST API provides four different endpoints for four different capabilities.

| Capability          | Endpoint Path                                                                                              | Description                                                                       |
| ------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| Generate Chat       | [`/models/{modelName}/chat-generations`](/docs/ai/agentforce/references/models-api#operation/generateChat) | Generate a response based on a list of messages representing a chat conversation. |
| Generate Embeddings | [`/models/{modelName}/embeddings`](/docs/ai/agentforce/references/models-api#operation/generateEmbeddings) | Create an embedding vector representing the input text.                           |
| Generate Text       | [`/models/{modelName}/generations`](/docs/ai/agentforce/references/models-api#operation/generateText)      | Generate a response based on the prompt provided.                                 |
| Submit Feedback     | [`/feedback`](/docs/ai/agentforce/references/models-api#operation/submitFeedback)                          | Submit feedback for generated text.                                               |

### Choose a Model

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.

```bash
https://api.salesforce.com/einstein/platform/v1/models/sfdc_ai__DefaultOpenAIGPT4OmniMini/generations
```

The Models API supports models from various Salesforce-enabled providers. See [Supported Models](https://developer.salesforce.com/docs/ai/agentforce/supported-models.md).

### Provide Headers

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 Request

Make a POST request to one of [the Models REST API endpoints](/docs/ai/agentforce/references/models-api?meta=summary). This example demonstrates a call to the `generations` endpoint.

```bash
curl --location 'https://api.salesforce.com/einstein/platform/v1/models/sfdc_ai__DefaultOpenAIGPT4OmniMini/generations' \
--header 'Authorization: Bearer ••••••' \
--header 'Content-Type: application/json' \
--header 'x-sfdc-app-context: EinsteinGPT' \
--header 'x-client-feature-id: ai-platform-models-connected-app' \
--data '{
    "prompt": "James Lee is a financial advisor, living in San Diego. His phone number is 867-5309. Generate a story about his work and life."
}'
```

**tip:** 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](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-authentication.md).

And here’s a sample response.

```json
{
  "id": "chatcmpl-9AMuFltdq7M5ntZVvQcAkgyWhfoas",
  "generation": {
    "id": "333127bd-2d5d-41e8-9781-59a1a18ed69f",
    "generatedText": "Once upon a time in sunny San Diego, there lived a diligent and experienced financial advisor named James Lee. With a passion for numbers and a knack for helping others achieve their financial goals, James had built a reputation as a trusted advisor in the community.\n\nJames had always been fascinated by the world of finance. From a young age, he would spend hours poring over financial newspapers and studying the stock market. As he grew older, his passion only intensified, leading him to pursue a degree in finance from a prestigious university...",
    "contentQuality": {
      "scanToxicity": {
        "isDetected": false,
        "categories": [
          {
            "categoryName": "identity",
            "score": 2.0e-5,
          },
          {
            "categoryName": "hate",
            "score": 0.0,
          },
          {
            "categoryName": "profanity",
            "score": 3.0e-5,
          },
          {
            "categoryName": "violence",
            "score": 2.0e-5,
          },
          {
            "categoryName": "sexual",
            "score": 1.5e-4,
          },
          {
            "categoryName": "physical",
            "score": 0.0,
          }
        ]
      }
    },
    "parameters": {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null
    }
  },
  "moreGenerations": null,
  "prompt": null,
  "parameters": {
    "created": 1712258359,
    "usage": {
      "completion_tokens": 607,
      "prompt_tokens": 39,
      "total_tokens": 646
    },
    "model": "gpt-35-turbo",
    "system_fingerprint": null,
    "object": "chat.completion"
  }
}
```

## Next Steps

After you successfully call the API, refer to these topics to optimize your implementation.

- [Supported Models](https://developer.salesforce.com/docs/ai/agentforce/supported-models.md)
- [Rate Limits for Models API](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-rate-limits.md)
- [Specify Languages and Locales with Models API](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-languages-and-locales.md)
- [Toxicity Scoring with Models API](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-toxicity-scoring.md)
- [Data Masking with Models API](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-data-masking.md)
- [Get Generation Feedback Using Models API](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-feedback.md)
- [Access Models API with Apex](https://developer.salesforce.com/docs/ai/agentforce/guide/access-models-api-with-apex.md)
- [Build Lightning Web Components and Flows with Models API](https://developer.salesforce.com/docs/ai/agentforce/guide/models-api-build-lwc-flow.md)
- [Models REST API Reference](/docs/ai/agentforce/references/models-api?meta=summary)

## See Also

- _Salesforce Help_: [Agentforce and Einstein Generative AI](https://help.salesforce.com/s/articleView?id=ai.generative_ai.htm)
- _Salesforce Help_: [External Client Apps](https://help.salesforce.com/s/articleView?id=xcloud.external_client_apps.htm)
