APRIL: API Synthesis with Automatic Prompt Optimization and Reinforcement Learning
Hua Zhong, Shan Jiang, Sarfraz Khurshid
TL;DR
APRIL targets the challenge of synthesizing new APIs from large libraries by marrying Automatic Prompt Optimization (APO) with Reinforcement Learning from Verifiable Rewards (RLVR). By iteratively refining prompts for a frozen LLM and fine-tuning via test-driven rewards, APRIL achieves high accuracy and reliability in generating functional APIs for scientific Python libraries. The approach is validated on 81 tasks across NumPy, SciPy, and scikit-learn, outperforming a baseline with manually engineered prompts and achieving a 93.8% overall test-passing rate. The combination of automated test-generation via Gemini CLI and the APO/RLVR loop demonstrates a scalable, low-interaction pathway for component-based API synthesis in large codebases, with strong practical implications for automated library extension. Overall, APRIL provides a robust framework for reliable API synthesis that leverages modern LLM capabilities while grounding outputs in verifiable, automated assessments.
Abstract
APIs are central to modern software development, yet composing new APIs from large libraries is difficult due to the exponential search space; traditional component-based synthesis relies on costly exploration and hand-crafted specifications. While large language models (LLMs) can generate implementations from natural language, hallucinations and limited access to up-to-date contextual information often yield incorrect code. In this paper, we present APRIL, an approach that combines LLM-based synthesis with Automatic Prompt Optimization (APO) and Reinforcement Learning from Verifiable Rewards (RLVR): APO iteratively refines prompts for a frozen model, while RLVR fine-tunes the policy toward functional correctness, producing an efficient synthesis pipeline. Evaluated on 81 real-world APIs from widely used scientific Python libraries and benchmarked against instruction-tuned but unfine-tuned LLMs guided by expert prompts, APRIL achieves substantial improvements. These results indicate that integrating APO and RLVR provides a robust, scalable path for component-based API synthesis in large libraries.
