Similar issue.
The syntax you are using is GitLab's shorthand route used within GitLab's web interface to access raw file contents directly. But the official Rest interface fails as well:
curl --header "JOB-TOKEN: <token>" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/files/<file>/raw?ref=<git-ref>"