There are a couple different approaches to endpoint interpolation with splines.
One way is to add an additional point to either end of the curve, which is not part of the original data set. Moving this invisible "guide" point around will change the shape of the end segments of the curve. So, if you have $n$ actual data points, you'd use $n+2$ points for the spline interpolation, with $2$ "guide" points. (Note that you would have the curve itself not pass through these guide points, but just use them for tangent calculations.)
Another way is to take a one-sided difference. This, in a sense, "clamps" the calculation within the boundaries of the data set. For example, with an equation like this:
$$p_i-p_{i-1}+p_{i+1}$$
For the $n=0$ case, you can just take
$$p_0-p_0+p_1$$
By replacing out-of-bounds points with a boundary point. Similarly, for $i=n$, we get $p_n-p_{n-1}+p_n$.
This means any $i-1$ is calculated as $\max(i-1,0)$ and $i+1$ is $\min(i+1,n)$, for points $p_0,p_1,\dots,p_n$.
I've found that a one-sided difference tends to give visually reasonable results and doesn't require choosing any "guide" points.