In many inverse and optimization problems, the computation of the gradient of the response-displacements and tractions-at the boundary of specimens due to a variation of the geometry is needed. Since finite difference techniques are error prone due to the difference parameter and are computationally expensive, a formulation to compute this gradient by direct differentiation is developed based on the boundary integral equation used for the standard Boundary Element Method.The formulation is implemented and tested for the case of arbitrarily shaped cavities and inclusions in a bounded or unbounded solid in the case of harmonic elastodynamics in 2D. The formulation is developed and studied independently of the discretization and of the parametrization of the change of geometry. The gradient is compared to some simple analytically solvable problems as well as complicated ones solved by centered finite differences for the sake of comparison. All of the cases give very stable and accurate results, both in static and dynamic elasticity. q