Difference in SIP protocol for Trunks vs. Endpoints

The channel driver (either chan_sip or chan_pjsip) if properly configured will parse, interpet, and place that information on the callerid store which is accessible using CALLERID[1]. Otherwise you could manually get the header using something like PJSIP_HEADER[2] and parse it yourself.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Function_CALLERID
[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Function_PJSIP_HEADER