Should I use bigint or varchar(20) as primary key, performance-wise, for Postgres? I have 18 character long IDs I get from an API, and I currently store them as varchar(20). They are used as primary and foreign keys. Is it better in my case, to use bigint instead of a string type, performance-wise?

Since JavaScript cannot deal with bigints, they are converted by default to string, but I could set columns to be bigint, if that will help.
Definitely store as a bigint: this uses 8 bytes, while an 18 character string uses 19 bytes.