A fully managed platform in Microsoft Foundry for hosting, scaling, and securing AI agents built with any supported framework or model
Hi @Ashish Kumar Jha welcome to the Microsoft Q&A community.
Yes the behavior you describe strongly points to a Code Interpreter / chart-generation path problem, rather than a general agent or model problem.
Microsoft's current Foundry documentation explicitly says Code Interpreter is the component responsible for running Python and generating charts.https://learn.microsoft.com/th-th/azure/foundry/agents/how-to/tools/code-interpreter?view=foundry&utm_source=chatgpt.com&pivots=python
What I would check first
Because ordinary questions work but a chart request produces HTTP 500, isolate the failure in this order:
- Ask for a calculation
-
"Calculate 12345 * 6789 using Python."
-
- Ask it to execute Python without creating a file
-
"Use Python to calculate the mean of [1,2,3,4,5]."
-
- Ask for a chart without an uploaded file
-
"Use Python to create a simple matplotlib line chart for x=[1,2,3], y=[2,4,6]. Save it as chart.png."
-
- Then test with your actual CSV/XLSX input. If #1/#2 work but #3 fails, you've narrowed it specifically to Code Interpreter's graphical/file-output path.
There is precedent for exactly this issue
Microsoft Q&A has reports of Azure AI Foundry returning server_error specifically when code_interpreter generates graphs. One report describes calculations working while graph generation fails, including cases where an image ID is produced but the corresponding file isn't available.
So I would not immediately rewrite your agent code based only on this 500.
Also check your model/deployment
Microsoft recommends checking the current regional and model availability for Code Interpreter because support varies by model/region.https://learn.microsoft.com/th-th/azure/foundry/agents/how-to/tools/code-interpreter?view=foundry&utm_source=chatgpt.com&pivots=python
If you're using something like gpt-4.1-mini, there's an especially interesting precedent: a Microsoft Q&A report found that Code Interpreter calculations worked but graph generation failed, while gpt-4.1 worked.https://learn.microsoft.com/en-us/answers/questions/5641829/server-error-occurs-in-azure-ai-foundry-when-gener?utm_source=chatgpt.com
So, as a diagnostic, try the same agent/tool configuration with another supported model deployment.
Verify your Code Interpreter configuration
For the current Foundry Agents API, the configuration should conceptually contain a Code Interpreter tool, e.g.:
"tools": [
{
"type": "code_interpreter",
"container": {
"type": "auto"
}
}
]
If you're using a file, the container can include the uploaded file IDs. Microsoft's current REST example uses this pattern for a CSV → Python → PNG workflow.https://learn.microsoft.com/bs-latn-ba/azure/foundry/agents/how-to/tools/code-interpreter?utm_source=chatgpt.com&pivots=python
The expected workflow is:
user prompt → agent → Code Interpreter → Python/matplotlib → generated file → response/file citation
If the request dies with HTTP 500 before you get a normal tool result, that is useful evidence that the failure is occurring on the Azure/Foundry service side rather than being a Python exception in your application.
One important distinction
If your error is literally:
openai.InternalServerError: Error code: 500
{
'error': {
'message': 'The server had an error processing your request...',
'type': 'server_error'
}
}
then this is not the same as Python code inside Code Interpreter throwing an exception.
A Python exception would normally be returned as part of the agent/tool execution, allowing the agent to potentially retry or correct the code. Code Interpreter is specifically designed to iteratively modify and rerun failed Python code.https://learn.microsoft.com/en-us/azure/foundry-classic/agents/how-to/tools-classic/code-interpreter?view=foundry-classic&utm_source=chatgpt.com&pivots=python
Your error is occurring at the API request level.
What I'd need to diagnose your case precisely
Please paste these 4 things (remove your endpoint/key/project IDs):
1. Model/deployment:
e.g. gpt-4.1 / gpt-4.1-mini / ...
2. Foundry SDK/package versions:
e.g. openai==...
azure-ai-projects==...
azure-ai-agents==...
3. Agent creation code:
The part where you create/configure the agent and Code Interpreter.
4. Request/run code:
The part where you send the user prompt to the agent.
Also tell me whether this works:
"Use Python to calculate 2 + 2"
but this fails:
"Use Python to create a simple bar chart of [10,20,30]."
With those details, I can pinpoint whether you're dealing with model compatibility, Foundry API/SDK version mismatch, Code Interpreter configuration, generated-file handling, or an Azure-side service issue.
N/B: I have generated the above answer using co-pilot as an AI tool. Also I have validated and updated the AI output.