What am I doing wrong here? I have no problem calling the DALL-E Image creation API, but I get the following error when calling the image variation API:
"'image' is a required property"
However, as you can see, I have the 'image' property defined. If I specify the Content-Type header as 'application/json' (which works fine for the image creation API), I get the following error instead:
"Invalid Content-Type header (application/json; charset=utf-8), expected multipart/form-data. (HINT: If you're using curl, you can pass -H 'Content-Type: multipart/form-data')"
Here is my code:
byte[] bits = null; //filled with actual image bits
var body = new
{
image = Convert.ToBase64String(bits),
n = 1,
size = "1024x1024"
};
var contentType = "multipart/form-data";
var uri = "https://api.openai.com/v1/images/variations";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer " + c_ApiKey);
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", contentType);
var content = new StringContent(
Newtonsoft.Json.JsonConvert.SerializeObject(body), Encoding.UTF8, contentType);
var response = await client.PostAsync(uri, content);
var result = await response.Content.ReadAsStringAsync();
}