Code interpreter allows your AI assistant to execute Python code in a sandboxed environment. The model can write and run code to perform calculations, analyze data, generate visualizations, and solve problems that require computation.
{
"organization_id": "org_your_org_id",
"assistant_id": "asst_abc123",
"tools": [{"type": "code_interpreter"}],
"inputs": [{"role": "user", "content": "What is the compound interest on $10,000 at 7% for 20 years?"}]
}The model will write and execute Python code to calculate the answer, then present the result.
| Mode | Behavior |
|---|---|
auto | Model uses code when computation is needed (recommended) |
on | Always run code before responding |
off | Disable code interpreter |
When code is executed, the response includes a code_interpreter_call output item:
{
"output": [
{
"type": "code_interpreter_call",
"id": "ci_abc123",
"status": "completed",
"code": "principal = 10000\nrate = 0.07\nyears = 20\nresult = principal * (1 + rate) ** years\nprint(f'${result:,.2f}')",
"outputs": [
{"type": "text", "text": "$38,696.84"}
]
},
{
"type": "message",
"role": "assistant",
"content": [{"type": "output_text", "text": "$10,000 at 7% for 20 years grows to $38,696.84."}]
}
]
}The code interpreter can:
- Mathematical computations — Arithmetic, statistics, financial calculations
- Data analysis — Process CSV/JSON data, compute aggregates, find patterns
- String manipulation — Parse, format, transform text
- Algorithm execution — Sort, search, graph algorithms
- File processing — Read and analyze uploaded files (with file retrieval enabled)
- Execution environment is sandboxed (no network access, no file system writes)
- Maximum execution time: 30 seconds per code block
- No external package installation (standard library and common scientific packages are available)
- Currently in development — availability may vary by plan
- "Calculate the ROI on these sales figures"
- "Parse this JSON and tell me the average value"
- "Sort this list and find duplicates"
- "Convert these temperatures from Fahrenheit to Celsius"
- System Tools Overview — All available built-in tools
- File Retrieval — Feed files into the code interpreter
- Agentic Workflows — Multi-step tool chaining
- Assistants — Configuring tools on an assistant