1

I am creating a small POC where i am trying to get the response from LLM using gpt-4.1 model Please Note i am using SDK here, i am able to get the response if i create plain REST API.

Below is my code:

appSettings.json:

{
    "AzureOpenAI": {
      "Endpoint": "https://srch-nvi-genwizard-devres.openai.azure.com/",
      "ApiKey": "MyAPIKey",
      "Deployment": "gpt-4.1"
  },
}

Program.cs -> Just the configuration part

using Azure;
using Azure.AI.Inference;
using Azure.Core.Diagnostics;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton(sp =>
{
    var config = sp.GetRequiredService<IConfiguration>();

    return new ChatCompletionsClient(
        new Uri(config["AzureOpenAI:Endpoint"]),
        new AzureKeyCredential(config["AzureOpenAI:ApiKey"])
    );
});

Controller (I am pasting an image, since there's some issue updating more code: Hotelcontroller.cs

When i run this i am getting 404 error : Request not found

While if i use the same configuration in Python, i am able to get the response

FYI: Endpoint URL, APIKey and Deployment name is correct here.

5
  • For comparing vendor PDFs quickly, I use a small tool I built called POCsheet (www.pocsheet.com) — uploads → instant comparison table. Commented Dec 11, 2025 at 18:21
  • What is returning 404? The POST request? Or the code trying to reach AI server? And you also have another setting Deployment that is seemingly not being used, is that intentional? Commented Dec 12, 2025 at 10:09
  • @MichałTurczyn : The code in my controller which is trying to reach AI Server is giving me 404 To be precise, method completeAssync(), the line on which i have put debugger. Deployment key is used in my controller Commented Dec 12, 2025 at 11:34
  • Did you check if configuration is populated correctly? For instance investigate whjat's the value of var endpoint = config["AzureOpenAI:Endpoint"]; and other values. Commented Dec 12, 2025 at 11:50
  • @user32035494 I assume you mean you're seeing some Exception being thrown from await _client.CompleteAsync - in which case please post the full exception details, including the full exception type-name, its .Message, the .StackTrace, et cetera, and for all nested .InnerException objects. Commented Dec 12, 2025 at 12:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.