Developer tools · Research feature

Study Tests Multi-Model Approach to Improve API Recommendation Reliability

A new method uses multiple machine learning models to reduce unreliable API suggestions, especially for rarely used functions.

Adapted from research by Aoi Matsuda, Fumio Machida, David Lo.

arXiv preprint revision · 2026-04-30 · Attribution & reuse
In this article
Editorial illustration of stacked plates.

Editor’s introduction

The study evaluates a technique called NvRec, which combines five machine learning models—CodeBERT, CodeT5, MulaRec, UniXcoder, and CodeT5+—to improve the reliability of API recommendations. It measures performance by tracking true accept rate, rejection rate, and false rejection rate across different model combinations and filtering strategies. The three-version configuration with CodeT5, MulaRec, and UniXcoder achieves a true accept rate of 83.8% and a rejection rate of 80.7% when only highly reliable candidates are considered. The five-version setup reaches a true accept rate of 83.1% with a lower rejection rate of 69.0% through simple majority voting, indicating better balance between acceptance and rejection. The research shows that using multiple models helps suppress recommendations involving infrequently used APIs, which are more prone to errors.

Introduction

Application Programming Interfaces (APIs) define the methods for accessing the functionality provided by software libraries and frameworks. Software developers call library functions through the API to efficiently implement the application code. However, to identify appropriate methods in a given application context, developers should comprehend the functionality of individual APIs from their documentation, which is prohibitively demanding when there are a vast number of available APIs. Although many coding tasks can be automated by AI and coding agents, human developers still need to be responsible for the code to ensure reliability.

To support developers in finding appropriate API methods, several recommendation techniques have been presented. The conventional API recommendation techniques are largely divided into single-API recommendations and API method sequence recommendations. For example, Heinemann et al. proposed a single API recommendation technique that analyzes identifiers, such as variable names and method names, in the source code and recommends a relevant API method based on the code’s context. For the API method sequence recommendation, Gu et al. proposed DeepAPI, which uses a deep learning model to generate API method sequences from natural language queries. Recently, Large Language Models (LLMs) have also been used for API recommendation. For instance, Irsan et al. achieved higher-precision API method sequence recommendation by inputting both natural language queries and source code into an ML model. Ma et al. presented CAPIR, which decomposes coarse-grained requirements into fine-grained ones and composes API method sequences by retrieving relevant APIs with an LLM.

Although machine learning (ML)-based API recommendations achieve remarkable performance, ML models inherently depend on large source code datasets for training. The distribution of datasets for programming tasks often exhibits a long-tail property, which poses a challenge to the quality of API recommendations, especially for tail API methods. Recommendation results containing tail API methods tend to be unreliable. Adopting such unreliable API recommendations can introduce bugs into the resulting software, leading to additional development and debugging costs.

API Usage and Challenges

An API provides an interface for using the functionality of software components, such as operating systems, middleware, libraries, and frameworks. For example, the Java API, the standard library for Java, provides functionality for file I/O, network communication, and GUI development. Developers can efficiently develop applications by using not only these standard libraries but also APIs provided by third parties.

Due to the large number of available libraries and frameworks, it is not easy to quickly identify the necessary functionalities and APIs during program development. A single library or framework often has multiple functionalities, making it time-consuming to find appropriate APIs. Furthermore, to use an API correctly, it is necessary to precisely understand the consequences of the API call. However, the documentation describing the overview and usage of APIs is not always sufficiently maintained. If the documentation is not well-maintained, developers may misuse the API and generate buggy code. The use of APIs is essential for efficient software development, but quickly and accurately identifying the desired API remains a challenge.

API Method Sequence Recommendation

In this study, we focus on API method sequence recommendation for programs written in Java. In object-oriented languages such as Java, APIs are concretely realized as methods defined in classes and interfaces. Therefore, we refer to each individual method provided by a library or framework as an API method. An API method is represented as a string that connects the class name and the method name with a dot, such as List.add or File.exists. Furthermore, we define an API method sequence as an ordered list of API methods invoked in accordance with dependencies and data flows to accomplish a specific functionality or task.

An API method sequence recommendation is a sequence-to-sequence task that takes a natural language query and a source code context as input and outputs a sequence of API methods to implement. Unlike single-API recommendation tasks, this task requires accurately inferring both the combination of API methods and their invocation order required to realize the target functionality. In this study, we follow the task definition and dataset introduced by Irsan et al.. The dataset is constructed from a large collection of Java projects released by Martins et al., where method information is extracted using the Eclipse JDT parser. Each data instance consists of a method declaration, the method body, and the associated Javadoc annotation.

Long-Tail Property and Head & Tail API Methods

The long-tail property poses a fundamental challenge for ML-based API method sequence recommendations. ML models are typically trained to minimize the average prediction error over the entire dataset, which biases them toward accurately recommending head API methods that are well represented in the training data. As a result, recommendations involving tail API methods, for which only limited training data are available, tend to suffer from lower accuracy.

Comparative Analysis of ML-based API Recommendation

Existing studies addressed the challenge of long-tail distribution in ML-based API sequence recommendations. However, these studies did not discuss how different ML models produce different recommendation results for tail API methods. Even if one model recommends an incorrect API method, another model may recommend the correct one. The diversity of ML models’ recommendation capabilities can be exploited to improve the reliability of API sequence recommendations.

In summary, the comparative analysis gives the following insights: 1) the API recommendation capability of ML models differs for head and tail APIs, 2) there is room to leverage the unique recommendation capabilities of different ML models and 3) it is likely that all ML models correctly predict in common for head APIs. Based on this observation, we propose an API recommendation method that leverages the diverse capabilities of ML models in their recommendations.

Overview of the proposed method

We propose N-version API recommendation (NvRec) that aims to improve the reliability of API method sequence recommendations by filtering unreliable recommendations using multiple versions of ML models. Instead of designing new ML models and training them on large code datasets, NvRec provides a framework for leveraging pre-trained ML models to generate more reliable API recommendations. To suppress unreliable outputs, NvRec predicts tail cases for given inputs and discards them, while multi-version inference is applied for the head case to generate reliable recommendation results.

Model Profile

The statistics recorded in the profile represent the performance characteristics of individual ML models for each API method. Therefore, the model profile provides a cheat sheet for selecting reliable models for a given API method in the inference step.

Tail Analyzer

In the inference step, we do not know if the input natural language query and source code context are in a tail case. Therefore, we introduce Tail Analyzer to predict whether the input belongs to the tail case. Tail Analyzer is trained on the same dataset as the API method sequence recommendation task; however, the learning objective and labels differ. Following Zhou et al., we use the binary head/tail labels provided in their dataset, which are defined based on the frequency of API methods in the training data. Specifically, an input instance is labeled a tail case if its ground-truth API method sequence contains API methods categorized as tail APIs under the frequency-based criterion. For this task, the input is a single string that concatenates the natural language query and the source code context, and the output is a binary flag indicating whether the input corresponds to a tail case. If the input is predicted as the head case, the recommended API method sequence is likely to consist solely of head API methods, yielding reliable API recommendations. Thus, in this case, we use N-version ML inferences to make a careful API sequence recommendation. Conversely, if the input is predicted as a tail case, the recommended API method sequence likely consists of tail APIs, leading to unreliable API recommendations. As NvRec aims to reduce unreliable API recommendations, we drop the request and do not proceed with the next step in the tail case.

Filtering

Recorded filtering (R-Filter): The filter checks whether all API methods included in the recommended sequence are recorded in the model profile. If any of the API methods do not exist in the model profile, the recommended sequence is deemed unreliable and dropped from the candidates.

Head filtering (H-Filter): The filter checks the tail flag of all the API methods included in the candidate sequence. If one or more tail API methods are included, the recommended sequence is deemed unreliable and is dropped from the candidates.

Recorded and head filtering (RH-Filter): The filter checks both the past prediction record and the tail flag for the API methods in the recommended sequence. This filter is the combination of the R-filter and the H-filter. If any one of the API methods does not exist in the record or is flagged as a tail, the recommended sequence is dropped from the candidates.

Output Decision

After filtering unreliable recommendation candidates, the final API method sequence recommendation result is selected by a decision rule. If more than one API method sequence candidate remains, the majority vote of the candidates is applied. If the majority reaches consensus on the same API method sequence, the result is selected as the final output. On the other hand, if the majority vote does not reach consensus on a specific API method sequence, the final output is determined by applying one of the following decision methods.

Reliability-score based decision (score-based): For each API sequence recommendation candidate, the reliability score is computed based on the model profile. The reliability score is defined as the geometric mean of the accuracy rates of all the API methods in the sequence.

Research Questions

To evaluate the effectiveness of NvRec, we set the following research questions. RQ1. How effective is Tail Analyzer alone in improving the reliability of API method sequence recommendation? RQ2. How does NvRec improve the reliability of API method sequence recommendation? RQ3. How is the reliability of API method sequence recommendation affected by different output decision rules? RQ4. Which filtering method is the most effective for improving the reliability of API method sequence recommendation?

Experimental Setup

For the input and output length constraints, we followed the default configurations of each model implementation. CodeBERT and CodeT5 were originally trained with a maximum input length of 256 tokens and a maximum output length of 100 tokens. MulaRec allows longer outputs, supporting up to 256 output tokens. UniXcoder and CodeT5+ also accept a maximum input length of 256 tokens and a maximum output length of 100 tokens.

Evaluation Methodology

To evaluate the effectiveness of Tail Analyzer, we first compare the performance of individual ML models with and without applying Tail Analyzer. We then evaluate three-version and five-version configurations of NvRec under different combinations of filtering methods (R-Filter, H-Filter, and RH-Filter) and output decision rules (Simple Rejection, Score-based, and Best model).

Note that in this paper, the term accuracy is used only for evaluating Tail Analyzer as a binary classifier, whereas the recommendation performance is evaluated primarily by TAR, RR, and FRR. RR represents the proportion of input instances that are rejected by Tail Analyzer, the filtering step, or the output decision rule. TAR measures the proportion of accepted API method sequence recommendations that exactly match the ground-truth sequence, reflecting the reliability of the system among the outputs that are actually returned to users. For a single ML model without Tail Analyzer, TAR is equal to the accuracy since it does not have rejections. The FRR denotes the proportion of rejected outputs that could have resulted in a correct recommendation if they had not been discarded. A rejected correct output refers to a recommendation that is filtered out despite being potentially correct according to the majority vote of candidate sequences. Since such outputs are unnecessarily removed, a lower FRR is preferable.

Reliability Improvement by NvRec

Next, we compare the detailed performance of NvRec between a representative three-version configuration and the five-version configuration. For the three-version NvRec, we report the results of the best-performing three-model combination (CodeT5, MulaRec, UniXcoder) under all combinations of filtering methods and output decision rules. For the five-version NvRec, we report the results under the same set of filters and decision rules.

Implications to practical usage

The evaluation results reveal that NvRec can achieve significantly higher reliability than individual recommendation models by proactively dropping unreliable recommendations. The ability to drop unreliable recommendations is practically important as developers can reduce the risk of API misuse caused by inappropriate recommendations. Such high reliability is particularly required in high-assurance software development contexts and for novice and beginner developers. However, as observed in our empirical study, higher RRs indicate that improved reliability comes at the cost of a high rejection rate, which significantly limits the availability of the recommendation tool. Although incorrect API recommendations do not exactly match the correct answers, they may still offer hints for developing or improving the code. Thus, practical tools can also leverage rejected API recommendations to help developers with lower-confidence alerts, enabling them to carefully accept or reject the recommendations.

Internal Validity

To mitigate the threat, we reuse the string-parsing function used in the study by Irsan et al. and unify the conversion of model outputs into lists of API method sequences. By adopting the same evaluation infrastructure as MulaRec, we minimize threats to internal validity arising from inconsistencies in how outputs are interpreted.

External Validity

First, the diversity of the evaluated models is inherently limited. In this study, we initially evaluate three-version configurations based on CodeBERT, CodeT5, and MulaRec. Although these models have been widely used in prior work, they do not necessarily produce similar outputs for the same inputs. To increase model diversity, we additionally include code-related models with different architectures, namely CodeT5+ and UniXcoder, in our comparative evaluation.

As an important direction for future work, we plan to evaluate NvRec on additional datasets, including benchmarks for other programming languages and newly constructed datasets, in order to further examine the generalizability of our findings across a broader range of settings.

Conclusion and Future Work

We proposed a reliable API method sequence recommendation approach, NvRec, which leverages multiple ML models to suppress unreliable API recommendations entailing tail APIs. Through extensive evaluations, the best NvRec configuration achieves a TAR of 83.8%, a RR of 80.7%, and a FRR of 32.2%, demonstrating substantially higher reliability than the best individual model. Our results show that Tail Analyzer solely improves the TAR of individual models. In addition, in the three-version configuration, combining models with diverse error patterns leads to higher TAR. In the five-version configuration, avoiding filtering and aggregating recommendations via simple majority voting tends to be more effective. NvRec can be configured with different ML models, filtering rules, and output decision rules to strike a desirable balance between reliability and efficiency.

Despite these promising results, the proposed approach incurs a relatively high rejection rate. NvRec is designed to proactively eliminate recommendations deemed unreliable, which inevitably results in a non-negligible number of inputs for which no recommendation is returned. This behavior prioritizes safety and reliability, but it may reduce the opportunity for providing recommendations in practical deployment scenarios. An important direction for future work is therefore to refine filtering strategies and output decision rules in order to maintain a high TAR while reducing the rejection rate. Moreover, since the N-version inference framework is not limited to API recommendation, it has the potential to be extended to other code generation and recommendation tasks.