This directory contains comprehensive API documentation for the LLM Optimization Platform.
api_specification.yaml- Complete OpenAPI 3.0 specification with all endpoints, schemas, and examplesapi_documentation.html- Interactive Swagger UI documentation with custom styling and features
../tests/test_api_documentation.py- Comprehensive test suite to validate documentation accuracy
Open the interactive API documentation in your browser:
# Serve the documentation locally
cd docs
python -m http.server 8080
# Then open http://localhost:8080/api_documentation.htmlOr if you have the API server running:
# Access via the API server (if serving static files)
curl http://localhost:5000/docs/api_documentation.htmlThe OpenAPI specification can be used with various tools:
# Generate client SDKs
openapi-generator generate -i api_specification.yaml -g python -o ./python-client
# Validate the specification
swagger-codegen validate -i api_specification.yaml
# Import into Postman
# File > Import > api_specification.yamlRun the documentation validation tests:
cd ..
python -m pytest tests/test_api_documentation.py -v- Development:
http://localhost:5000/api/v1 - Production:
https://api.llm-optimization.com/v1
All endpoints require API key authentication:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:5000/api/v1/health- Text Generation: 100 requests/minute
- Batch Operations: 10 requests/minute
- Other Endpoints: 1000 requests/minute
GET /health- Basic health checkGET /status- Detailed system statusGET /ready- Readiness probe
GET /models- List available modelsGET /models/{id}- Get model details
POST /generate- Generate textPOST /generate/batch- Batch generation
GET /commercial/test- Test API connectionsGET /commercial/models- List commercial models
POST /cost/track- Track API usagePOST /cost/estimate- Estimate costsPOST /cost/compare- Compare model costsGET /cost/budget/status- Budget statusGET /cost/analytics- Usage analytics
PUT /feedback/evaluation/{id}- Update feedbackGET /feedback/stats- Feedback statistics
GET /monitoring/health- Monitoring statusGET /monitoring/metrics/system- System metricsGET /monitoring/alerts- Active alerts
curl -X POST http://localhost:5000/api/v1/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Write a short story about AI",
"model_id": "gpt-4",
"max_tokens": 100,
"temperature": 0.7
}'curl -X POST http://localhost:5000/api/v1/cost/track \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "gpt-4",
"input_tokens": 50,
"output_tokens": 100,
"latency_ms": 1500
}'curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:5000/api/v1/statusAll endpoints return standardized error responses:
{
"error": "validation_error",
"message": "Invalid request parameters",
"details": "max_tokens must be between 1 and 2048",
"timestamp": "2024-01-01T00:00:00Z"
}validation_error- Invalid request parametersauthentication_error- Missing or invalid API keyrate_limit_exceeded- Too many requestsmodel_not_found- Requested model unavailablegeneration_error- Text generation failedinternal_server_error- Unexpected server error
{
"success": true,
"data": { ... },
"timestamp": "2024-01-01T00:00:00Z"
}{
"success": false,
"error": "error_code",
"message": "Error description",
"timestamp": "2024-01-01T00:00:00Z"
}The Swagger UI documentation includes:
- Click "🔑 Set API Key" button to store your API key
- Automatically includes API key in all test requests
- Persistent storage in browser localStorage
- Interactive request forms for all endpoints
- Real-time request/response testing
- Parameter validation and examples
- Detailed descriptions for all endpoints
- Request/response schemas with examples
- Parameter validation rules
- Error response documentation
The documentation includes comprehensive tests to ensure accuracy:
- OpenAPI 3.0 specification compliance
- All required fields present
- Valid YAML syntax
- Reference integrity
- All implemented endpoints documented
- Request/response schemas match implementation
- Examples work with actual API
- Error responses documented
- Documentation serves correctly
- Interactive features work
- API key authentication functions
- Examples execute successfully
When adding new endpoints or modifying existing ones:
- Update OpenAPI Spec - Add/modify endpoint in
api_specification.yaml - Add Examples - Include request/response examples
- Update Tests - Add validation tests in
test_api_documentation.py - Test Documentation - Run tests to ensure accuracy
- Update README - Add any new sections or usage examples
- Descriptions: Clear, concise endpoint descriptions
- Examples: Working examples for all request/response formats
- Validation: Proper parameter validation rules
- Error Handling: Document all possible error responses
- Security: Include authentication requirements
- Versioning: Maintain backward compatibility
- Swagger Editor - Online OpenAPI editor
- OpenAPI Generator - Generate client SDKs
- Swagger Codegen - Code generation
- Postman - API testing with OpenAPI import
- Swagger Validator - Online spec validation
- OpenAPI Spec Validator - Python validation
- Spectral - OpenAPI linting
- Swagger UI - Interactive documentation
- ReDoc - Alternative documentation renderer
- GitBook - Documentation platform
- Stoplight - API documentation platform