Gemini AI SDK for .NET and ASP.NET Core enables developers to use Google's state-of-the-art generative AI models to build AI-powered features and applications.
I've built an app that uses the Gemini AI api, and it works great locally on my machine on localhost.
When I publish the app to Azure I keep getting 400 errors when my code hits the AI
System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()at Mscc.GenerativeAI.GenerativeModel.GenerateContent(GenerateContentRequest request)at Mscc.GenerativeAI.GenerativeModel.GenerateContent(String prompt, GenerationConfig generationConfig, List1 safetySettings, List1 tools, ToolConfig toolConfig)
My code is real simple. It fails on the simple example
string apiKey = "blah blah";
var prompt = "Write a story about a magic backpack.";
var googleAI = new GoogleAI(apiKey: apiKey);
var model = googleAI.GenerativeModel(model: Model.Gemini15Flash);
var response = model.GenerateContent(prompt).Result;
Console.WriteLine(response.Text);
In Azure, I've set the key to 'unrestricted' and it still fails.
Is there a setting I need to change on Azure? Or the Google API settings?
I've built an app that uses the Gemini AI api, and it works great locally on my machine on localhost.
When I publish the app to Azure I keep getting 400 errors when my code hits the AI
System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()at Mscc.GenerativeAI.GenerativeModel.GenerateContent(GenerateContentRequest request)at Mscc.GenerativeAI.GenerativeModel.GenerateContent(String prompt, GenerationConfig generationConfig, List
1 safetySettings, List1 tools, ToolConfig toolConfig)
My code is real simple. It fails on the simple example
In Azure, I've set the key to 'unrestricted' and it still fails.
Is there a setting I need to change on Azure? Or the Google API settings?
I have billing enabled for the API.
Thanks