I guess the context is the routing library. You can do this by constraining the slack variable of a dimension.
Suppose cumul(d)[i] and cumul(d)[j] correspond to dimension d.
Suppose you have a dimension d' (d_prime), for which the transition callback always returns 0.
You can constrain slack(d_prime) == solver->MakeElement(function_callback, cumul(d)[i], cumul(d)[j]).
To take this into account in the objective you need to add d' to the cost function with:
d_prime->SetSpanCostCoefficientForAllVehicles(1);
Note: performance of such a model might not be great (aka slow to solve). You can make it better by returning the lower bound of all f(cumul(d)[i], cumul(d)[j]) in the transit callback of d' and removing this lower bound from the function callback when you create the Element expression.
Vincent