Assistant API code_interpreter output not populated

I am unable to get the output of the code_interpreter tool.
When asking the model something like:

calculate the first 10 Fibonacci numbers with code

The assistant (using gpt-4o) will create code that looks like this:

# Define a function to calculate the first ten Fibonacci numbers
def first_n_fibonacci(n):
    fibonacci = [0, 1]
    while len(fibonacci) < n:
        next_fib = fibonacci[-1] + fibonacci[-2]
        fibonacci.append(next_fib)
    return fibonacci[:n]

# Calculate the first ten Fibonacci numbers
first_ten_fibonacci = first_n_fibonacci(10)
first_ten_fibonacci

This code will obviously produce an output like this:

[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

I am, however, unable to capture that output anywhere. The tool call that is surfaced through the streaming api (on_tool_call_done) does not contain any output:

tool_call: {
  "id": "call_Emd7wTr3ajvWWmyUDQUYzw7S",
  "code_interpreter": {
    "input": "# Define a function to calculate the first ten Fibonacci numbers\ndef first_n_fibonacci(n):\n    fibonacci = [0, 1]\n    while len(fibonacci) < n:\n        next_fib = fibonacci[-1] + fibonacci[-2]\n        fibonacci.append(next_fib)\n    return fibonacci[:n]\n\n# Calculate the first ten Fibonacci numbers\nfirst_ten_fibonacci = first_n_fibonacci(10)\nfirst_ten_fibonacci",
    "outputs": []
  },
  "type": "code_interpreter",
  "index": 0
}

The same is the case when iterating through the run steps – the associated run step also has not output:

{
  "id": "step_Zn3d0x96pT5pcLs0Mq3sePcZ",
  "assistant_id": "asst_KYmXGbetJhWA7orV7NO2nOhX",
  "cancelled_at": null,
  "completed_at": 1719834747,
  "created_at": 1719834745,
  "failed_at": null,
  "last_error": null,
  "object": "thread.run.step",
  "run_id": "run_5v6fQsDyAtwRS0znW84tQ3ZF",
  "status": "completed",
  "step_details": {
    "tool_calls": [
      {
        "id": "call_Emd7wTr3ajvWWmyUDQUYzw7S",
        "code_interpreter": {
          "input": "# Define a function to calculate the first ten Fibonacci numbers\ndef first_n_fibonacci(n):\n    fibonacci = [0, 1]\n    while len(fibonacci) < n:\n        next_fib = fibonacci[-1] + fibonacci[-2]\n        fibonacci.append(next_fib)\n    return fibonacci[:n]\n\n# Calculate the first ten Fibonacci numbers\nfirst_ten_fibonacci = first_n_fibonacci(10)\nfirst_ten_fibonacci",
          "outputs": []
        },
        "type": "code_interpreter"
      }
    ],
    "type": "tool_calls"
  },
  "thread_id": "thread_pwxd0jWxHQ2WE6hjiG8QJqQY",
  "type": "tool_calls",
  "usage": {
    "completion_tokens": 96,
    "prompt_tokens": 0,
    "total_tokens": 96
  },
  "expires_at": null
}

Somehow, the assistant gets the output and then gives me the right answer, but I want to provide debug capabilities and show the user what exactly the code_interpreter returned.

Is this a bug or what am I missing here?

3 Likes

Hi Daniel, just fix your prompt like “calculate the first 10 Fibonacci numbers with code and run de algoritm”

In my case, I use Python. Once you run the thread and it reaches the complete status, then:

run_steps = client.beta.threads.runs.steps.list(
  thread_id=thread.id,
  run_id=run.id
)

for i in range(len(run_steps.data)):
    sd = data[i].step_details
    if sd.type == "tool_calls":
        tool_call_detail = sd.tool_calls        
        print(tool_call_detail[0].code_interpreter.input) # Algoritm
        print(tool_call_detail[0].code_interpreter.outputs[0].logs) # Output

my output was:

Algoritm:  # Function to generate the first n Fibonacci numbers and print them
def fibonacci_with_print(n):
    fib_sequence = [0, 1]
    print(fib_sequence[0])
    print(fib_sequence[1])
    while len(fib_sequence) < n:
        next_num = fib_sequence[-1] + fib_sequence[-2]
        fib_sequence.append(next_num)
        print(next_num)
    return fib_sequence[:n]

# Run the algorithm to generate and print the first 10 Fibonacci numbers
fibonacci_numbers_with_print = fibonacci_with_print(10)
fibonacci_numbers_with_print
Output:  0
1
1
2
3
5
8
13
21
34

Hope this was useful for you.

1 Like

That’s a great workaround, but the behavior is still not what I would expect based on how it works in other environments and other Python runtimes/boxes.

Images behave as expected, as shown when the code requests to see one, but for some reason, anything other than multimedia doesn’t.

The output seems to combine STDOUT, STDERR (Only sometimes?) and, for some reason, cell outputs in a notebook-like way but only for files.

Have you seen any documentation explaining what we are supposed to see as outputs?

I am also seeing this behavior as well. These logs used to populate back in May which leads me to believe this was a bug introduced sometime in June. The last thread I have that included these output logs was on June 3rd.

Perhaps these log outputs are being hidden now for security reasons? Would love to get some input from OpenAI here :pray:

Example of thread that had output logs: thread_ROsLxmQ4WWXkCx7crNoj0FJx

Another post that has the same issue: Why the outputs of code interpreter are EMPTY? - #4 by 23randomforest