{
"error": {
"message": "Missing required parameter: 'content'.",
"type": "invalid_request_error",
"param": "content",
"code": "missing_required_parameter"
}
}
< /code>
var messageBody = new
{
role = "user",
content = "Summarize the attached file.", //
attachments = new[]
{
new
{
file_id = fileId, // The uploaded file's ID from Azure OpenAI
tools = new[] { new { type = "file_search" } } // Also tried "code_interpreter"
}
}
};
// Serialize message body
var jsonMessageBody = JsonSerializer.Serialize(messageBody, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
});
Console.WriteLine($"JSON Payload: {jsonMessageBody}");
// Prepare HTTP content
var messageContent = new StringContent(jsonMessageBody, Encoding.UTF8, "application/json");
// Send POST request to Azure OpenAI API
var response = await client.PostAsync(
$"{AzureEndpoint}/openai/threads/{threadId}/messages?api-version=2024-08-01-preview",
messageContent
);
// Read response
var messageJson = await response.Content.ReadAsStringAsync();
Console.WriteLine($"API Response: {messageJson}");
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Error sending message: {response.StatusCode} - {messageJson}");
}
< /code>
Why is the API still returning "Missing required parameter: 'content'" despite the field being present in the JSON?
Подробнее здесь: https://stackoverflow.com/questions/794 ... ending-mes