API Model Problem - Please Help

my error:

{
“error”: {
“message”: “you must provide a model parameter”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}

My Code:

using System.Net.Http.Headers;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace WinFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private async void button1_Click(object sender, EventArgs e)
    {

        string apiEndpoint = "https://api.openai.com/v1/completions";


        string apiKey = "*********************************************";


        string prompt = txtInput.Text;


        var values = new Dictionary<string, string>
     {
        { "prompt", prompt },
        { "model", "text-davinci-002" },
        { "max_tokens", "150" },
        { "temperature", "0.5" },
        { "stop", "\n" }
     };


        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
            var content = new FormUrlEncodedContent(values);
            var response = await httpClient.PostAsync(apiEndpoint, content);
            var responseContent = await response.Content.ReadAsStringAsync();

            // API'den gelen cevabı TextBox'a yazdırma
            txtOutput.Text = responseContent;
        }
     }
    }
}

}

You’re sending the data as a form, instead of JSON.

3 Likes