Welcome to the community!
Could you try to add echo on the variable before the steps that you use to call it to verify that pipeline is correctly showing the variable as the following example:
script: - echo "$API_URL"
This should create an echo output of the variable in the pipeline build where you can use to verify if the variable is correctly showing the output you configure as below example:
If it's not showing any echo output or the output is different from what you expected then the variable may be using a secure variable or you have a conflict variable that you may have configured in the deployment variable or the workspace variable.
I hope this helps.