If your external headers are going to be using functions from other libraries (e.g., Boost), then the above templating approach will likely fail, as Stan can’t auto-differentiate through functions in external libraries (in most cases). In that case, you would also need to define the gradients wrt each input for the function.
If this is something that you need, I put together an example of how to do this for a Boost function in this post (and rest of thread): Gamma distribution quantile and inverse quantile function - #28 by andrjohns