admin管理员组

文章数量:1291148

I'm trying to set up a Semantic Kernel project and I would like to connect it to the OpenRouter api. To the best of my knowledge, their API should be compatible with the OpenAI API, therefore a connection should work. I used

var httpClient = new HttpClient
{
  Timeout = TimeSpan.FromMinutes(10)
};        

builder.AddOpenAIChatCompletion(
  modelId:"deepseek/deepseek-r1", 
  apiKey: @"my Open Router Api Key", 
  endpoint: new Uri(";), 
  httpClient: httpClient);

I get a 404 error when I try this and I don't know why. When I use the OpenAI API everything works.

I also tried using this HttpClientHandler so that the requests go out to OpenRouter but it didn't work either and I get a 405 error:

public class MyHttpMessageHandler : HttpClientHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        if (request.RequestUri != null && request.RequestUri.Host.Equals("api.openai", StringComparison.OrdinalIgnoreCase))
        {
            request.RequestUri = new Uri($";);
        }

        return base.SendAsync(request, cancellationToken);
    }
}

本文标签: cSemantic Kernel with OpenRouterStack Overflow