AI Coding Agents Show No Preference for REST over Non-REST APIs
Many APIs deviate from REST conventions, using POST for all write operations and naming endpoints after actions, such as /updateBin. It was anticipated that AI agents would struggle with these non-REST APIs, as REST aligns HTTP methods with intent. However, this expectation did not hold true when agents had access to documentation.
In a comprehensive evaluation involving 1,356 runs across six models from two vendors, agents performed equally well with REST, POST-only, and RPC-style APIs, maintaining similar success rates and costs in failed calls. Without documentation, REST APIs significantly outperformed the others, as agents could infer REST URLs from established conventions, while non-REST APIs presented a guessing challenge.
Challenges with Non-REST APIs
The term “non-REST” typically restricts the API to GET and POST methods and replaces resource paths with verb-named endpoints, potentially hindering agent performance. For instance, a model accustomed to REST might mistakenly use DELETE and encounter a 404 error. Such errors could lead to fewer completed tasks or necessitate additional calls.
Testing Different API Styles
A fictional inventory API named Binstock was created, presented in three styles with identical data and behavior. The testing utilized Dev Proxy and its CrudApiPlugin, resetting in-memory data for each run. A total of 15 tasks were created, including read and write operations. Agents were provided with the base URL and an OpenAPI description of the API, totaling 900 runs.
| Style | Success | Runs without a failed call | Tokens per run |
|---|---|---|---|
| REST | 100% | 82% | ≈70k |
| POST-only | 100% | 82% | ≈70k |
| RPC | 99.7% | 77% | ≈71k |
The only failure in the RPC style was due to a timeout. REST utilized approximately 700 fewer tokens per run compared to RPC. All models exhibited equivalent performance across comparisons.
Performance Without Documentation
To assess performance without documentation, Claude Sonnet 5.5 and GPT-6.1 Terra were given only the base URL. Neither model successfully guessed an endpoint like /updateBin. On the RPC API, agents averaged around 28 failed calls before giving up. The POST-only style performed moderately better, as its read operations utilized the same paths as REST.
| Model | REST | POST-only | RPC |
|---|---|---|---|
| Claude Sonnet 5.5 | 93% | 40% | 0% |
| GPT-6.1 Terra | 97% | 60% | 0% |
REST runs generally succeeded, with agents averaging about 10 failed calls per task while attempting to locate the correct URLs. The conventions inherent in REST helped agents approximate the correct endpoints.
Longer Tasks and Overall Performance
A small Node.js project was created to simulate longer tasks, requiring agents to fix a failing unit test and apply updates to Binstock. Claude Sonnet 5.5 and GPT-6.1 Terra executed eight handovers twice in each style, totaling 96 runs. All runs were successful, with token usage remaining consistent across styles.
Future Testing Directions
Future research could involve testing an RPC API that lists its operations at the root URL or within 404 errors to see if agents can complete tasks without documentation. Another approach would involve scaling up the API to test whether agents begin to select incorrect endpoints as complexity increases.
Implications for API Development
For developers maintaining non-REST APIs, there is no immediate need to alter their design, as agents utilized POST-only and RPC APIs with comparable efficiency to REST when documentation was accessible. Developers should ensure agents can access documentation and consider enabling APIs to self-describe.
Conclusion
The tested AI coding agents did not struggle with non-REST APIs, provided they had access to documentation. Every model effectively utilized POST-only and RPC APIs as reliably and cost-effectively as REST.
Related link: aka.ms
Source: Microsoft Developer Blogs