Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Vertex Endpoint and 404 from C# SDK

We have a Vertex Endpoint that we can successfully call from the `gcloud` CLI through a Service Account as follows:

 

gcloud auth activate-service-account --key-file $JSON_KEY_FILE
gcloud ai endpoints raw-predict $ENDPOINT_ID \
  --project=$PROJECT_ID \
  --region=$LOCATION_ID \
  --http-headers=Content-Type=application/json \
  --request=$JSON_BODY

 

 

 
it also works with curl:

 

gcloud auth activate-service-account --key-file $JSON_KEY_FILE
curl -X POST "https://$LOCATION_ID-aiplatform.googleapis.com/v1beta1/projects/$PROJECT_ID/locations/$LOCATION_ID/endpoints/$ENDPOINT_ID:rawPredict" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  --data $JSON_BODY​

 

 

However, if we try to do the same with either the `Google.Cloud.AIPlatform.V1` or `Google.Cloud.AIPlatform.V1beta1` C# NuGet packages, we get a 404 error:

 

using Xunit;
using Google.Apis.Auth.OAuth2;
using Google.Protobuf;
using Google.Api;
using System.Threading.Tasks;
using Google.Cloud.AIPlatform.V1Beta1; // also tried just V1

namespace UnitTests;

public class UnitTest1
{
    [Fact]
    public async Task Test1()
    {
        var jsonKeyFile = "<path to json key file>";
        var credential = GoogleCredential.FromFile(jsonKeyFile);
        var client = await new PredictionServiceClientBuilder
        {
            Credential = credential,
        }.BuildAsync();
        var response = await client.RawPredictAsync(  // error: 404
            "projects/<project-id>/locations/<location-id>/endpoints/<endpoint-id>",
            new HttpBody
            {
                Data = ByteString.CopyFromUtf8(@"<json body>")
            });
    }
}

 

 

 
The full error received is:
```
Grpc.Core.RpcException : Status(StatusCode="Unimplemented", Detail="Bad gRPC response. HTTP status code: 404")
at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass0_0`2.<<WithRetry>b__0>d.MoveNext()
```

Any suggestions.
0 1 121
1 REPLY 1

Heard back from some internal Google contacts that the`Google.Cloud.AIPlatform.V1` and `Google.Cloud.AIPlatform.V1beta1` C# NuGet packages have not been updated to use the new Location-prefixed version of the `aiplatform.googleapis.com` domain.  Therefore, I had to workaround the above by getting an accessToken and constructing the Authorization header myself like done in the `curl` example.  The code to get an accessToken:

var credential = GoogleCredential
    .FromFile(jsonKeyFile)
    .CreateScoped("https://www.googleapis.com/auth/cloud-platform");
var accessToken = await credential.UnderlyingCredential.GetAccessTokenForRequestAsync();