> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrieve recommendations

> Retrieves recommendations from selected AI models.

**Required ACL:** `search`

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  // Initialize the client
  var client = new RecommendClient(
    new RecommendConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
  );

  // Call the API
  var response = await client.GetRecommendationsAsync(
    new GetRecommendationsParams
    {
      Requests = new List<RecommendationsRequest>
      {
        new RecommendationsRequest(
          new RelatedQuery
          {
            IndexName = "<YOUR_INDEX_NAME>",
            ObjectID = "objectID",
            Model = Enum.Parse<RelatedModel>("RelatedProducts"),
            Threshold = 42.1,
          }
        ),
      },
    }
  );

  // print the response
  Console.WriteLine(response);
  ```

  ```dart Dart theme={"system"}
  // Initialize the client
  final client = RecommendClient(
      appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');

  // Call the API
  final response = await client.getRecommendations(
    getRecommendationsParams: GetRecommendationsParams(
      requests: [
        RelatedQuery(
          indexName: "<YOUR_INDEX_NAME>",
          objectID: "objectID",
          model: RelatedModel.fromJson("related-products"),
          threshold: 42.1,
        ),
      ],
    ),
  );

  // print the response
  print(response);
  ```

  ```go Go theme={"system"}
  // Initialize the client
  client, err := recommend.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
  if err != nil {
    // The client can fail to initialize if you pass an invalid parameter.
    panic(err)
  }

  // Call the API
  response, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest(

    recommend.NewEmptyGetRecommendationsParams().SetRequests(
      []recommend.RecommendationsRequest{*recommend.RelatedQueryAsRecommendationsRequest(
        recommend.NewEmptyRelatedQuery().SetIndexName("<YOUR_INDEX_NAME>").SetObjectID("objectID").SetModel(recommend.RelatedModel("related-products")).SetThreshold(42.1))})))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


  // print the response
  print(response)
  ```

  ```java Java theme={"system"}
  // Initialize the client
  RecommendClient client = new RecommendClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

  // Call the API
  GetRecommendationsResponse response = client.getRecommendations(
    new GetRecommendationsParams().setRequests(
      Arrays.asList(
        new RelatedQuery()
          .setIndexName("<YOUR_INDEX_NAME>")
          .setObjectID("objectID")
          .setModel(RelatedModel.RELATED_PRODUCTS)
          .setThreshold(42.1)
      )
    )
  );

  // print the response
  System.out.println(response);
  ```

  ```js JavaScript theme={"system"}
  // Initialize the client
  const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initRecommend();

  // Call the API
  const response = await client.getRecommendations({
    requests: [{ indexName: 'indexName', objectID: 'objectID', model: 'related-products', threshold: 42.1 }],
  });


  // print the response
  console.log(response);
  ```

  ```kotlin Kotlin theme={"system"}
  // Initialize the client
  val client = RecommendClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

  // Call the API
  var response =
    client.getRecommendations(
      getRecommendationsParams =
        GetRecommendationsParams(
          requests =
            listOf(
              RelatedQuery(
                indexName = "<YOUR_INDEX_NAME>",
                objectID = "objectID",
                model = RelatedModel.entries.first { it.value == "related-products" },
                threshold = 42.1,
              )
            )
        )
    )


  // print the response
  println(response)
  ```

  ```php PHP theme={"system"}
  // Initialize the client
  $client = RecommendClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

  // Call the API
  $response = $client->getRecommendations(
      ['requests' => [
          ['indexName' => '<YOUR_INDEX_NAME>',
              'objectID' => 'objectID',
              'model' => 'related-products',
              'threshold' => 42.1,
          ],
      ],
      ],
  );


  // print the response
  var_dump($response);
  ```

  ```python Python theme={"system"}
  # Initialize the client
  # In an asynchronous context, you can use RecommendClient instead, which exposes the exact same methods.
  client = RecommendClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

  # Call the API
  response = client.get_recommendations(
      get_recommendations_params={
          "requests": [
              {
                  "indexName": "<YOUR_INDEX_NAME>",
                  "objectID": "objectID",
                  "model": "related-products",
                  "threshold": 42.1,
              },
          ],
      },
  )


  # print the response
  print(response)
  ```

  ```ruby Ruby theme={"system"}
  # Initialize the client
  client = Algolia::RecommendClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

  # Call the API
  response = client.get_recommendations(
    Algolia::Recommend::GetRecommendationsParams.new(
      requests: [
        Algolia::Recommend::RelatedQuery.new(
          index_name: "<YOUR_INDEX_NAME>",
          algolia_object_id: "objectID",
          model: "related-products",
          threshold: 42.1
        )
      ]
    )
  )


  # print the response
  puts(response)
  ```

  ```scala Scala theme={"system"}
  // Initialize the client
  val client = RecommendClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

  // Call the API
  val response = Await.result(
    client.getRecommendations(
      getRecommendationsParams = GetRecommendationsParams(
        requests = Seq(
          RelatedQuery(
            indexName = "<YOUR_INDEX_NAME>",
            objectID = "objectID",
            model = RelatedModel.withName("related-products"),
            threshold = 42.1
          )
        )
      )
    ),
    Duration(100, "sec")
  )

  // print the response
  println(response)
  ```

  ```swift Swift theme={"system"}
  // Initialize the client
  let client = try RecommendClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")

  // Call the API
  let response = try await client
      .getRecommendations(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest
              .relatedQuery(RelatedQuery(
                  indexName: "<YOUR_INDEX_NAME>",
                  threshold: 42.1,
                  model: RelatedModel.relatedProducts,
                  objectID: "objectID"
              ))]))

  // print the response
  print(response)
  ```
</CodeGroup>

<Card icon="folder-code" horizontal="true" title="See the full API reference" arrow="true" href="/doc/rest-api/recommend/get-recommendations">
  For more details about input parameters
  and response fields.
</Card>
