dotnet-docs-samples icon indicating copy to clipboard operation
dotnet-docs-samples copied to clipboard

Getting error with Claude - Sonnet models

Open ambitiousrahul opened this issue 5 months ago • 0 comments

I am using Google.Cloud.AIPlatform.V1 version 3.38.0 (.NET based SDK for Vertex AI) and trying to connect to GCP: Anthropic models(already enabled on Vertex AI).

 var payloadObj = new
  {
      max_tokens = 500,
      temperature = 0.7,
      top_p = 1.0,
      top_k = 1.0,
      stop_sequences = new string[] { },
      messages = new[]
      {
        new {
            role = "user",
            content = new[]
            {
                new {
                    type = "text",
                    text = "This is my first hi to you. Write good morning message for me"
                }
            }
        }
      },
      anthropic_version = "vertex-2023-10-16"
  };

 var json = JsonConvert.SerializeObject(payloadObj);
var instances = JsonParser.Default.Parse<Google.Protobuf.WellKnownTypes.Value>(json);

   // Create the PredictRequest
   PredictRequest request = new PredictRequest
   {
       //Endpoint = endpoint.ToString(),
       EndpointAsEndpointName = endpoint,
       Instances = { instances }
   };
   PredictResponse response = await geminiClient.PredictAsync(request);

But, I am always getting following error on PredictAsync method

Grpc.Core.RpcException: 'Status(StatusCode="InvalidArgument", Detail="{"type":"error","error":{"type":"invalid_request_error","message":"messages: Field required"}}")'

ambitiousrahul avatar Jul 17 '25 06:07 ambitiousrahul