Thinktecture Logo

Wire-debugging Semantic Kernel code talking to OpenAI (and other) LLM APIs through HTTPS

Author: Christian Weyer • Published: 04.07.2023 • Category: AI, Semantic Kernel

There was this small issue I was running into when trying to move a Semantic Kernel (SK) demo application from an older version to the most recent version 0.16.230615.1-preview.

The code just did not work as before. I did not change anything other than moving to the new code of SK (OF COURSE, I did not… famous last words, eh?).

The result was not an error. It also was not the correct result – rather, it was somehow repeating my question as the Q&A answer.
Something was really weird.

Enter a question or press enter to quit: What is SK?      
🤖:What is SK?
Enter a question or press enter to quit: 
Code language: Bash (bash)

So, what to do now?
Of course, the truth in distributed systems, especially with “REST” APIs, can be found on the wire.

Therefore, I took a debugging proxy to look at which data goes back and forth between my SK-based C# code and the OpenAI API.

As I am working on an Apple MBP, my choice for a debugging proxy is Charles.

I quickly wrote down a custom IWebProxy class and wired it up in my code with an appropriately configured HttpCient:

var httpClient = new HttpClient(new HttpClientHandler { Proxy = new LocalDebuggingProxy() });

var kernel = Kernel.Builder
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", config["OpenAi:ApiKey"], httpClient: httpClient)
    .WithOpenAITextCompletionService("text-davinci-003", config["OpenAi:ApiKey"], httpClient: httpClient)
Code language: C# (cs)
class LocalDebuggingProxy : IWebProxy
    public ICredentials? Credentials { get; set; }

    public Uri? GetProxy(Uri destination)
        return new Uri("");

    public bool IsBypassed(Uri host)
        return false;
Code language: C# (cs)

Then, I started the application again and asked the same question… and this is what Charles showed me.

Aha! There we go… now I know where to continue to try to fix my sample.
(And yes, this is simply a bug in SK not properly propagating this kind of error.)

The truth is always on the wire!

Aktuelle Research-Insights unserer Experten für Sie

Lesen Sie, was unsere Experten bei ihrem Research bewegt und melden Sie sich zu unserem kostenlosen Thinktecture Labs-Newsletter an.

Labs-Newsletter Anmeldung

Christian Weyer

I am one of the co-founders and the CTO of Thinktecture AG. As a Microsoft MVP, RD and Google GDE, I have spoken at a wide variety of software conferences and events around the world for over two decades - with passion and commitment, especially for distributed application architectures and cross-platform solutions. I really like to think and talk about both deeply technical facts as well as the real purpose of technologies. Feel free to get in touch with me directly via email at or on Twitter @christianweyer.

More about me →