You may be able to use regexp to modify it but a better way is to use a proxy redirect:
proxy_redirect http://foo.bar/baz/ /;
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
Any Location headers for foo.bar/baz/
will go to /
If you just want to redirect /baz/api
, that'll work too.
If any redirects are also adding the port, you'll need to add http://foo.bar:8080/baz/
as well (separate redirect).
Hope this helps!