Azure OpenAI Messages API throws 'content' parameter missing error despite providing content field

I’m having trouble with Azure OpenAI when trying to send messages with PDF attachments

I upload a document file successfully, create a new thread, then attempt to post a message that includes both text content and the uploaded file. The API keeps returning this error:

{
  "error": {
    "message": "Missing required parameter: 'content'.",
    "type": "invalid_request_error",
    "param": "content",
    "code": "missing_required_parameter"
  }
}

Here’s my request payload structure:

var requestPayload = new
{
    role = "user",
    content = "Please analyze this document and provide a summary.",
    attachments = new[]
    {
        new
        {
            file_id = uploadedFileId,
            tools = new[] { new { type = "file_search" } }
        }
    }
};

var jsonPayload = JsonSerializer.Serialize(requestPayload, new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});

var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");

var apiResponse = await httpClient.PostAsync(
    $"{azureEndpoint}/openai/threads/{threadId}/messages?api-version=2024-08-01-preview",
    httpContent
);

var responseText = await apiResponse.Content.ReadAsStringAsync();

if (!apiResponse.IsSuccessStatusCode)
{
    Console.WriteLine($"Request failed: {apiResponse.StatusCode} - {responseText}");
}

The content field is clearly included in my request, so why does Azure OpenAI still complain about it being missing?

Had a similar headache with this error a few weeks back. The problem isn’t actually with your content field - it’s how the request is being structured. When using attachments with the Messages API, you need to wrap your content in an array format instead of a simple string. Your content should be structured like this: content = new[] { new { type = "text", text = "Please analyze this document and provide a summary." } }. The API expects content to be an array of content blocks when attachments are involved, even if you only have one text block. This caught me off guard because the documentation isn’t super clear about when to use string vs array format for the content parameter. Once I switched to the array structure, the missing content error disappeared completely.

I encountered this exact issue last month and it turned out to be related to the API version I was using. The attachments parameter isn’t supported in all API versions, and when Azure OpenAI doesn’t recognize the structure, it sometimes fails to parse the content field properly. Try switching to the 2024-10-01-preview API version instead of 2024-08-01-preview. Also, make sure your Azure OpenAI resource actually supports the Assistants API with file attachments - not all regions or pricing tiers have this enabled yet. You can verify this by checking if you can create assistants with file_search tools through the Azure portal first. If that doesn’t work, you might need to upgrade your Azure OpenAI service tier or switch to a different region that supports these features.