I faced similar issues with Postgres linked tables because of different SQL syntax and also poorly implemented translation from IRIS dialect to your linked server dialect. The workaround is to add an instance of EnsLib.SQL.Operation.GenericOperation to your production and to execute SQL queries via ODBC/JDBC bypassing IRIS, something like:

Set operation = ##class(EnsLib.SQL.Operation.GenericOperation).%New("NameOfYourProductionComponent")
#Dim rs as EnsLib.SQL.GatewayResultSet
Set status = operation.Adapter.ExecuteQuery(.rs, "select 1", .args)
While (rs.Next()) {
   ...
}
Do rs.Close()

To be honest... no :) Actually I think I badly need a standalone terminal (but Studio is discontinued) or a Python/Java/C#/whatever library which is able to invoke arbitrary commands on a remote server and I'm just wondering if such libraries exist.

PS leveraging WebTerminal API looks attractive but it seems to me it doesn't expose Swagger/OpenAPI definitions

Great, thanks a lot, it works.

The real error messages are "ERROR #6162: Unable to create HTTP Authorization header for NTLM scheme." and "ERROR #6162: Unable to create HTTP Authorization header for Negotiate scheme." for both NTLM and Negotiate schemes respectively.

Does it mean that IRIS is unable to deal with these authentication schemes? The documentation says that NTLM is supported.

You have to cast your %CharacterStream to a specific implementation, say, to %GlobalCharacterStream. The latter one implements %GlobalStreamAdaptor, which inherits from %AbstractStream and %Stream.Object. Finally, the %Stream.Object class exposes the CopyFrom method which allows you to copy data from your %Stream.GlobalBinary instance (and vice versa)