TL;DR
Large language models (LLMs) are increasingly used for code generation, but their ability to generate correct web API integration code remains largely untested. This paper introduces WAPIIBench, a novel benchmark and evaluation pipeline, revealing that even state-of-the-art LLMs struggle significantly, with none solving more than 40% of tasks and frequently hallucinating API endpoints and parameters.
What Problem Does This Paper Address?
Modern software development heavily relies on integrating various services through web APIs. While LLMs show promise in automating code generation, their effectiveness in creating correct web API integration code is an open question. Developers need to understand complex API specifications, including methods, URLs, and numerous parameters, which can be challenging. This paper aims to systematically evaluate how well LLMs can generate this specific type of code, addressing the gap in understanding their capabilities and limitations in this crucial area.
Methods
The authors developed a comprehensive evaluation pipeline for benchmarking LLM-generated web API integration code. This pipeline consists of four stages:
- Dataset Creation: A dataset of API invocation tasks was created using OpenAPI specifications for real-world APIs (Asana, Google Calendar, Google Sheets, Slack). This involved generating task descriptions and corresponding correct request configurations.
- Code Generation: LLMs were tasked with generating JavaScript code using the Axios library to perform API invocations based on natural language descriptions and starter code.
- Code Execution: A controlled environment was used to execute the generated code, intercepting API requests to capture their configurations without sending them to actual servers.
- Correctness Analysis: The captured request configurations were compared against the ground-truth configurations and validated against API specifications to measure functional correctness and compliance. This involved a fine-grained analysis of various metrics, including correct implementations, URLs, methods, and arguments.
Datasets
The paper introduces WAPIIBench, a novel benchmark consisting of nearly 400 pairs of web API invocation tasks and their corresponding correct outcomes. This dataset was generated synthetically using Gemini 1.5 Pro and then manually reviewed and corrected to ensure quality and accuracy. The benchmark covers four real-world APIs: Asana, Google Calendar, Google Sheets, and Slack.
Key Insights and Ideas
- LLMs struggle with API integration: Despite their general coding prowess, LLMs exhibit significant weaknesses when it comes to generating correct web API integration code. This suggests that memorizing API specifications and correctly assembling them into functional code is a distinct challenge.
- Hallucinations are rampant: A major issue is the tendency of LLMs to "hallucinate"—generating incorrect or non-existent API endpoints, URLs, and parameter names. This highlights a critical reliability concern for LLM-generated code in production environments.
- Argument completion is slightly better, but still flawed: While providing the correct endpoint (argument completion setup) improves performance, LLMs still struggle to correctly utilize all parameters and avoid specification violations.
- Model size isn't everything: The study observed that medium-sized models sometimes underperform compared to smaller or larger variants within the same model family, indicating that model architecture and training data play a complex role.
- API specificity matters: LLMs perform differently across various APIs, likely due to the prevalence of those APIs in their training data. Google Calendar API tasks were generally handled better.
Key Results
- Low overall correctness: Even the best-performing open-source LLMs achieved only around 30% correct implementations in the full completion setup.
- Frequent endpoint and parameter errors: Hallucinated endpoint URLs occurred in up to 39% of tasks, and incorrect parameter names in up to 31% for some models.
- Argument completion improvement: In the argument completion setup, where the correct endpoint was provided, the best open-source model (Code Llama 70B) reached about 40% correctness.
- GPT-4o leads, but still imperfect: OpenAI's GPT-4o achieved the highest correctness rates (around 60% for full completion and 77% for argument completion), but still failed on a significant portion of tasks.
- Executability is high, correctness is low: While most generated code was executable (over 94%), the correctness of the executed requests was often poor.
Limitations and Future Work
The authors acknowledge several limitations:
- Simplified context: The evaluation used limited program context before the API invocation, which might not reflect real-world scenarios.
- Focus on outgoing requests: The evaluation only assessed the correctness of the outgoing API request, not how the incoming response is handled.
- Dataset limitations: The synthetic nature of the dataset might lead to placeholder values and limited use of optional parameters, potentially affecting generalizability. Prompt engineering could also significantly optimize model performance, but the authors opted for a consistent prompt for fair comparison.
Future work could explore:
- Investigating the impact of retrieval-augmented generation, fine-tuning, reasoning, feedback loops, and constrained decoding on improving LLM performance.
- Extending the benchmark to other languages and libraries beyond JavaScript and Axios.
- Developing more sophisticated evaluation methods that can capture nuances in API usage and response handling.
Summary updated