How to build a BAM header file with htslib in C++?
You're just looking in the wrong header file. The BCF stuff will be in vcf.h (you'll see the two functions you mentioned there).
With BAM files one doesn't typically need to add/remove headers, which is why there are not convenience functions for them. To add a header:

Increment hdr-&gt;ntargets
realloc(hdr-&gt;target_len, ...) and hdr-&gt;target_name.
You likely want to append the name/length to the end of hdr-&gt;target_name and hdr-&gt;target_len, respectively.

I don't think you need to update the dictionary or plain text for most uses (or at least I've never needed to).
Removing a chromosome would follow the reverse instructions, (you'd need to shift everything in the name and length arrays if you remove entries in the middle.
WARNING, doing this is prone to error!
I would strongly cautious you to be very careful when doing this. Please remember that the chromosome that entries are mapped to isn't actually stored in alignment entries themselves. Rather, they simply have an index into hdr-&gt;target_name, which saves space. Consequently, if you start adding/removing headers to/from a BAM file with alignments then you're going to have to modify all of the alignments to keep the correct alignment:chromosome associations. Otherwise you'll end up with completely useless results (this is the same caveat as with samtools reheader).