A repositopy has 2 branches - master (default) and stage. If I try to get file from branch stage by API, I get file from master. I use url ‘https://g.cnvl.io/api/v1/repos/myowner/myrepo/raw/gate.php?ref=stage’
I think you might want to use the contents rather than raw call.
At least in the docs (<host>/api/swagger) of my current gitea version, raw has no ref parameter, but contents does.
If you check out the swagger page, you can also try out the commands interactively to see whether things will work as expected.