API Performance Budget
A coding loop focused on optimizing API performance to ensure P95 latency stays under a defined target threshold. This loop iteratively runs load tests, analyzes bottlenecks, and implements optimizations until the goal is achieved or maximum iterations are reached.
Goal
Keep API latency within target
How to Run
Run this loop in any supported coding agent environment to continuously optimize API endpoints based on real-time load testing feedback.
- 01
Initialize Environment
Ensure api-load.js script exists with proper k6 load test configuration targeting the API endpoints.
- 02
Start Loop Execution
Execute the loop by prompting the agent to begin performance optimization cycles using k6 load testing.
- 03
Monitor Exit Condition
Allow the agent to iterate up to 10 times, automatically checking if P95 latency meets the target after each optimization.
Workflow Steps
- 01
Run load test
if P95 latency >= target
- 02
Analyze performance metrics and identify bottlenecks
after step 1
- 03
Implement performance optimizations
after step 2
- 04
Re-run load test
after step 3
- 05
Check P95 against target and decide exit or repeat
if iterations < 10 and P95 >= target
- 06
Exit loop successfully
if P95 < target
- 07
Exit loop after max iterations
if iterations >= 10 and P95 still >= target
Kickoff Prompt
Start the "API Performance Budget" loop. Goal: Keep API latency within target Max iterations: 10 Between iterations run: k6 run api-load.js Exit when: P95 latency below target Optimize the API to meet the P95 latency target defined in the load test script. Run iterative optimizations until the target is achieved or 10 iterations are completed. Self-pace this loop. After each iteration, run `k6 run api-load.js` and evaluate the output, and only continue if the exit condition is not met (P95 latency below target). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Do not modify database schemas or external services during optimization.
- ·Optimize only using standard library features and documented best practices.
- ·Ensure all changes are covered by existing or new unit/integration tests.
- ·Maintain original API functionality and contract compliance.
- ·Limit iterations to prevent infinite optimization loops.
Flow Diagram
Related loops — API
API
Resolve API Error Responses
This loop standardizes API error responses across the application to improve client-side error handling and debugging. It ensures all error responses follow a consistent structure (e.g., RFC 7807 Problem Details format) with appropriate HTTP status codes and machine-readable error codes.
API
Fix Failing Integration Endpoints
Automatically detects and resolves issues in failing API integration endpoints through iterative testing and code modifications.
API
Generate Missing API Docs
Automatically identifies and documents all undocumented API endpoints in the project. The agent iteratively generates OpenAPI/Swagger documentation until all endpoints meet the required documentation standards.