NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Leveraging Large Language Models to Improve REST API Testing

Myeongsoo Kim, Tyler Stennett, Dhruv Shah, Saurabh Sinha, Alessandro Orso

TL;DR

This paper introduces RESTGPT, a novel approach that uses Large Language Models (LLMs) to significantly improve REST API testing by extracting valuable information from natural language descriptions within API specifications. RESTGPT achieves higher precision and accuracy in generating test cases compared to existing methods, paving the way for more robust and efficient API testing.

What Problem Does This Paper Address?

Modern web applications heavily rely on REST APIs, but their increasing complexity makes thorough testing a significant challenge. Existing automated testing tools primarily focus on the structured data within API specifications (like OpenAPI), often overlooking the rich, human-readable descriptions that contain crucial semantic information and constraints. This oversight leads to suboptimal test coverage and the generation of invalid test inputs. While some tools attempt to extract rules from these descriptions, they are limited in the types of rules they can handle and often produce inaccurate results, requiring complex validation processes.

Methods

RESTGPT tackles this problem by leveraging the power of Large Language Models (LLMs), specifically GPT-3.5 Turbo. The core of the approach involves a "Rule Generator" that, guided by carefully crafted prompts, extracts machine-interpretable rules and parameter values from the natural language descriptions within an API specification. These prompts are designed around four key components: guidelines for rule extraction, specific cases to handle different scenarios (e.g., non-definitive descriptions, complex parameter relationships), grammar highlights for key operators, and output configurations for structured results.

The process begins with parsing the OpenAPI specification to identify both machine-readable and human-readable sections. The Rule Generator then uses few-shot learning with contextually rich instructions and examples to ensure relevant and precise outputs. Finally, RESTGPT augments the original API specification with these newly extracted rules and values, creating an "enhanced specification" that can be used by testing tools. A key innovation is that RESTGPT's approach achieves high accuracy without needing a separate validation process, which is a significant advantage over prior methods.

Datasets

The paper evaluates RESTGPT using nine RESTful services sourced from the NLP2REST study, which provided a ground truth for extracted rules. This allowed for a direct comparison with existing techniques. The authors also incorporated a comparison with ARTE, using metrics derived from the ARTE paper. No new datasets were introduced for training; instead, the focus was on evaluating the LLM's performance on existing API specifications.

Key Insights and Ideas

  • LLMs unlock hidden value in natural language descriptions: The paper demonstrates that LLMs can effectively interpret nuanced natural language descriptions in API specifications, extracting constraints and generating valid test inputs that traditional NLP methods struggle with.
  • Context is king: RESTGPT's ability to understand the context of parameters (e.g., recognizing "language" parameters relate to specific language codes) leads to significantly more relevant and accurate test data generation compared to tools that rely on keyword matching or external knowledge bases.
  • Eliminating the validation bottleneck: By achieving high precision directly, RESTGPT bypasses the need for expensive and time-consuming post-extraction validation steps, making the testing process more efficient.
  • Bridging the gap between human readability and machine interpretability: RESTGPT acts as a powerful bridge, translating the insights from human-readable documentation into actionable rules for automated testing tools.

Key Results

RESTGPT demonstrates impressive performance improvements:

  • Rule Extraction Precision: RESTGPT achieved a precision of 97%, significantly outperforming NLP2REST without validation (50%) and even NLP2REST with validation (79%).
  • Valid Input Generation: RESTGPT successfully generated syntactically and semantically valid inputs for 73% of parameters across analyzed services, a substantial improvement over ARTE's 17%.
  • Accuracy: In terms of accuracy for ARTE vs. RESTGPT, RESTGPT achieved an average of 72.68% compared to ARTE's 16.93%.

Limitations and Future Work

The authors acknowledge several avenues for future work:

  • Model Improvement: They plan to fine-tune LLMs on large datasets of API specifications from sources like APIs.guru and RapidAPI to enhance their ability to comprehend diverse API contexts. They also aim to develop lightweight LLMs for REST API testing that can run on commodity CPUs.
  • Expanding Fault Detection: Currently, RESTGPT primarily focuses on detecting faults that result in 500 server response codes. Future work will explore leveraging LLMs to detect a broader range of bugs, including CRUD semantic errors and producer-consumer discrepancies.
  • LLM-based Testing Approach: The researchers intend to develop a REST API testing tool that can leverage server messages. By using LLMs' semantic understanding, this tool could autonomously generate relevant tests based on server hints, ensuring that potential loopholes are not missed.

Summary updated

Abstract

The widespread adoption of REST APIs, coupled with their growing complexity and size, has led to the need for automated REST API testing tools. Current tools focus on the structured data in REST API specifications but often neglect valuable insights available in unstructured natural-language descriptions in the specifications, which leads to suboptimal test coverage. Recently, to address this gap, researchers have developed techniques that extract rules from these human-readable descriptions and query knowledge bases to derive meaningful input values. However, these techniques are limited in the types of rules they can extract and prone to produce inaccurate results. This paper presents RESTGPT, an innovative approach that leverages the power and intrinsic context-awareness of Large Language Models (LLMs) to improve REST API testing. RESTGPT takes as input an API specification, extracts machine-interpretable rules, and generates example parameter values from natural-language descriptions in the specification. It then augments the original specification with these rules and values. Our evaluations indicate that RESTGPT outperforms existing techniques in both rule extraction and value generation. Given these promising results, we outline future research directions for advancing REST API testing through LLMs.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
NLP2REST comparisonNLP2REST (without validation module)precision50%split: val
Source quote
L18: Our preliminary results demonstrate the significant advantage of our approach over existing tools. Compared to NLP2REST without the validation module, our method improves precision from 50% to 97%. Even when compared to NLP2REST equipped with its validation module, our approach still increases precision from 79% to 97%. Additionally, RESTGPT successfully generates both syntactically and semantically valid inputs for 73% of the parameters over the analyzed services and their operations, a considerable improvement over ARTE, which could generate valid inputs for 17% of the parameters only. Given these encouraging results, we outline a number of research directions for leveraging LLMs in other ways for further enhancing REST API testing.
NLP2REST comparisonRESTGPTprecision97%split: val
Source quote
L18: Our preliminary results demonstrate the significant advantage of our approach over existing tools. Compared to NLP2REST without the validation module, our method improves precision from 50% to 97%. Even when compared to NLP2REST equipped with its validation module, our approach still increases precision from 79% to 97%. Additionally, RESTGPT successfully generates both syntactically and semantically valid inputs for 73% of the parameters over the analyzed services and their operations, a considerable improvement over ARTE, which could generate valid inputs for 17% of the parameters only. Given these encouraging results, we outline a number of research directions for leveraging LLMs in other ways for further enhancing REST API testing.
NLP2REST comparisonNLP2REST (with validation module)precision79%split: val
Source quote
L18: Our preliminary results demonstrate the significant advantage of our approach over existing tools. Compared to NLP2REST without the validation module, our method improves precision from 50% to 97%. Even when compared to NLP2REST equipped with its validation module, our approach still increases precision from 79% to 97%. Additionally, RESTGPT successfully generates both syntactically and semantically valid inputs for 73% of the parameters over the analyzed services and their operations, a considerable improvement over ARTE, which could generate valid inputs for 17% of the parameters only. Given these encouraging results, we outline a number of research directions for leveraging LLMs in other ways for further enhancing REST API testing.
Analyzed services and their operationsRESTGPTparameters with syntactically and semantically valid inputs73%Parameter value generation across the analyzed services and their operations.
Source quote
L18: Our preliminary results demonstrate the significant advantage of our approach over existing tools. Compared to NLP2REST without the validation module, our method improves precision from 50% to 97%. Even when compared to NLP2REST equipped with its validation module, our approach still increases precision from 79% to 97%. Additionally, RESTGPT successfully generates both syntactically and semantically valid inputs for 73% of the parameters over the analyzed services and their operations, a considerable improvement over ARTE, which could generate valid inputs for 17% of the parameters only. Given these encouraging results, we outline a number of research directions for leveraging LLMs in other ways for further enhancing REST API testing.
Analyzed services and their operationsARTEparameters for which valid inputs were generated17%Compared with RESTGPT's parameter value-generation result; the validity criteria for AR…
Source quote
L18: Our preliminary results demonstrate the significant advantage of our approach over existing tools. Compared to NLP2REST without the validation module, our method improves precision from 50% to 97%. Even when compared to NLP2REST equipped with its validation module, our approach still increases precision from 79% to 97%. Additionally, RESTGPT successfully generates both syntactically and semantically valid inputs for 73% of the parameters over the analyzed services and their operations, a considerable improvement over ARTE, which could generate valid inputs for 17% of the parameters only. Given these encouraging results, we outline a number of research directions for leveraging LLMs in other ways for further enhancing REST API testing.
BibTeX
@misc{kim2023leveraging,
  author = {Myeongsoo Kim and Tyler Stennett and Dhruv Shah and Saurabh Sinha and Alessandro Orso},
  title = {{Leveraging Large Language Models to Improve REST API Testing}},
  year = {2023},
  eprint = {2312.00894},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.00894},
}
Figure