C#C
C#3y ago
kevin

❔ Misused header name

Hi, I get the following error and I'm not sure on how to fix it.

System.InvalidOperationException: 'Misused header name, 'content-type'. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.'


Heres my code:

            using var httpClient = new HttpClient();
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Post,
                RequestUri = new Uri($"https://api.openai.com/v1/{_model}/completions"),
                Headers =
            {
                { "Content-Type", "application/json" },
                { "Authorization", $"Bearer {_apiKey}" },
            },
                Content = new StringContent(JsonSerializer.Serialize(new
                {
                    prompt = question,
                    max_tokens = 50,
                    temperature = 0.7
                }))
            };
Was this page helpful?