Forum Discussion
Azure AI Foundry SDK File Attachment Issue
Problem Summary
We are unable to attach files to Azure AI Foundry agents using the Python SDK (`azure-ai-projects` and `azure-ai-agents`). **Every approach to file attachment results in a generic HTTP 500 error** from the Azure API:
```
HttpResponseError: (None) The server had an error processing your request.
Sorry about that! You can retry your request, or us through our help
center at oai-assistants@ if you keep seeing this error.
```
This occurs consistently across:
- Code Interpreter file attachments
- Vision/image file references
- All documented attachment patterns from Microsoft's official documentation
Environment Details
- **SDK Versions:**
- `azure-ai-projects`: 1.0.0
- `azure-ai-agents`: 1.1.0
- **Python**: 3.12
- **Azure Region**: East US 2
- **Model**: gpt-4o, gpt-5-mini
- **File Upload**: Files upload successfully to Azure AI Foundry (status: "processed")
- **Agent Creation**: Agents create successfully without file attachments
What We've Tried
Files Upload Successfully But Cannot Be Connected to Agents
While file upload and agent creation work individually, **we cannot link files to agents** - every attempt to connect them fails with HTTP 500:
# 1. File upload - No errors, but agent cannot access the file
with open("data.csv", 'rb') as f:
file_response = openai_client.files.create(file=f, purpose="assistants")
# Result: File ID returned, file status = "processed"
# Problem: File exists on Azure but no way to connect it to an agent
# 2. Agent creation without files - No errors, but cannot attach files later
agent = project_client.agents.create_agent(
model="gpt-4o",
name="test-agent",
instructions="You are helpful",
tools=[CodeInterpreterToolDefinition()]
)
# Result: Agent created successfully
# Problem: Agent exists but cannot access any files
❌ All Attempts to Connect Files to Agents Fail (HTTP 500)
Attempt 1: Message Attachments (per Microsoft docs)
from azure.ai.agents.models import MessageAttachment, CodeInterpreterToolDefinition
attachment = MessageAttachment(
file_id=file_id,
tools=[CodeInterpreterToolDefinition()]
)
message = project_client.agents.messages.create(
thread_id=thread_id,
role="user",
content="Analyze this file",
attachments=[attachment] # ❌ HTTP 500
)
**Request ID**: `649ec8ad5b8941804068be4f41ccb680`
Attempt 2: Thread Creation with Tool Resources
from azure.ai.agents.models import ToolResources, CodeInterpreterToolResource
tool_resources = ToolResources(
code_interpreter=CodeInterpreterToolResource(file_ids=[file_id])
)
thread = project_client.agents.threads.create(
tool_resources=tool_resources # ❌ HTTP 500
)
**Request ID**: `17501cc0daa8e0a4a7bcc95945231b10`
Attempt 3: Thread Update with Tool Resources
project_client.agents.threads.update(
thread_id=thread_id,
tool_resources=tool_resources # ❌ HTTP 500
)
**Request ID**: `418f1aeedb94b55504fcee444ae471ee`
Attempt 4: Agent Creation with Tool Resources (Microsoft's recommended approach)
Following the official documentation at: https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/code-interpreter-samples
from azure.ai.agents.models import (
ToolResources,
CodeInterpreterToolResource,
CodeInterpreterToolDefinition
)
# Upload file
file = openai_client.files.create(file=f, purpose="assistants")
# Create tool resources
tool_resources = ToolResources(
code_interpreter=CodeInterpreterToolResource(file_ids=[file.id])
)
# Create agent with files
agent = project_client.agents.create_agent(
model="gpt-4o",
name="test-agent",
instructions="You are helpful",
tools=[CodeInterpreterToolDefinition()],
tool_resources=tool_resources # ❌ HTTP 500
)
**Request ID**: `c2e1a86cfa0dd09d4448092a3139dae5`
Attempt 5: Vision with Image File Content (no code_interpreter)
message_content = [
{
"type": "text",
"text": "Please describe this image."
},
{
"type": "image_file",
"image_file": {
"file_id": file_id
}
}
]
message = project_client.agents.messages.create(
thread_id=thread_id,
role="user",
content=message_content # ❌ HTTP 500
)
**Request ID**: `401e53a5802d1e203e6fe92d74ad59f1`
Summary Table
| Approach | API Method | Code Interpreter | Result |
|----------|-----------|------------------|--------|
| Message attachments | `messages.create(attachments=[...])` | Yes | ❌ HTTP 500 |
| Thread creation | `threads.create(tool_resources=...)` | Yes | ❌ HTTP 500 |
| Thread update | `threads.update(tool_resources=...)` | Yes | ❌ HTTP 500 |
| Agent creation | `agents.create_agent(tool_resources=...)` | Yes | ❌ HTTP 500 |
| Vision image_file | `messages.create(content=[image_file])` | No | ❌ HTTP 500 |
Questions:
- **Has anyone successfully attached files to Azure AI Foundry agents using the Python SDK?**
- **Is there a specific Azure configuration, permission, or feature flag required for file attachments?**
- **Are file attachments only available in certain Azure regions or subscription tiers?**
- **Is this a known issue with the current SDK version?**
- **Are there any alternative approaches we haven't tried?**
Documentation followed: https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/code-interpreter-samples?pivots=python
Yes this was AI written - but human validated!