Use jq and especially jo for string and parameter creation.
Handle special-character-problems ( ‘ % $ and million others ) by url encoding your strings directly at the source. chatgpt api natively speaks urlencode.
I’ve tried base64, but the chatbot mentions in his answer that he/she was fed with base64 encoded stuff.
To encode use urlencode (who unfort can not read from stdin, you will have to do some xargs gymnastics) or, better, use perl: https://bytesandbones.wordpress.com/2023/03/23/encode-url-with-perl/