ChatGPT-4 API access from C#

I got the API working in test-davinci-03 but I can’t seem to get it right in gpt-4. It keeps giving me invalid_request_error (full text below). I have permission I am told via email. I can’t find anywhere that talks about C#. Am I missing somewhere?

“This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?”

GPT-4 uses the Chat completion endpoint and ChatML…

Welcome to the community. Hope you stick around.

So your answer is No I can’t use C#?

It has nothing to do with the language used. GPT4 uses the the chat completion endpoint. It says right there in the error message you are getting. use /v1/chat/completions instead of /v1/completions

1 Like

I tried that before I even posted here and it had no effect. I am guessing it has something to do with the way the content is created since the python code uses an openai routine and I use a json routine. I am porting it to python but I would rather be in C#.

It’s worth noting that the endpoints for “gpt-3.5-turbo” and “gpt-4” are distinct from that of “text-davinci-003”, and thus require different parameter formats. For seamless functioning, it is advisable to peruse the API documentation provided by OpenAI.

*It works well with POSTMAN.

1 Like

That was it. I needed to get it working in gpt-3.5-turbo first because the interface is so different and there is little in the way of examples for gpt-4 at the moment. Once gpt-3.5-turbo was working, I just changed the model and it worked.


Yes you can use it with C#, but in chat completion mode.
For example, like this:

// Create a chat completion request
var completionResult = await apiClient.ChatCompletion.CreateCompletion(
new ChatCompletionCreateRequest()
Messages = new List() {
new ChatMessage(“user”, “put your question like in playground”)
Model = Models.ChatGpt3_5Turbo,
Temperature = 0.0f,
MaxTokens = 100,
N = 1

// Check the response
if (completionResult.Successful)
return completionResult.Choices[0].Message.Content;

Hope this will help.