#Code Interpreter File ID

1 messages · Page 1 of 1 (latest)

orchid wadi
#

Hello,

The docs referenced below say that to retrieve file contents from code interpreter you have to get the container id and file id. i cant find these in a code interpreter output. can anyone help? using javascript. thanks

https://platform.openai.com/docs/guides/tools-code-interpreter
https://platform.openai.com/docs/api-reference/container-files/retrieveContainerFileContent

Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.

Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.

#

snippet of my code:

const openai = new OpenAI({ apiKey: env.OPENAI_API_KEY });
      const response = await openai.responses.create({
        model: "gpt-4.1-nano",
        tools: [{
          "type": "code_interpreter",
          "container": { "type": "auto" }
        }],
        //instructions: 'You are a financial-planning report generator.',
        input: `write a 4 line limrick export it as a pdf`, //sample prompt to test pdf
      });
      console.log('OpenAI response:', response);
      const interpreterCall = response.output.find(item => item.type === 'code_interpreter_call');
      if (interpreterCall) {
        console.log('OpenAI container_id:', interpreterCall.container_id);
        console.log('OpenAI file_id:', interpreterCall.id);
        const containerId = interpreterCall.container_id;
        const fileId = interpreterCall.id;
        const url = `https://api.openai.com/v1/containers/${containerId}/files/${fileId}/content`;
        // i dont know if this is the correct fileid. the axious call is erroring out "BAD REQUEST"

        //axios curl call to download the pdf
        try {
          const fileResponse = await axios.get(url, {
            responseType: 'arraybuffer', // to handle binary file content
            headers: {
              'Authorization': `Bearer ${env.OPENAI_API_KEY}`
            }
          });
          const fileContent = fileResponse.data;
          console.log('Retrieved file content length:', fileContent.byteLength);
          // Optionally, write the file content to disk or process as needed
        } catch (error) {
          console.error('Error retrieving file content:', error);
        }
      } else {
        console.log('No code interpreter call found.');
      }
halcyon marsh
#

the container id and file id can be found in the last output block from the response

#

theres different output types, like message, code_interpreter_call, etc. Essentially every step the ai took. I think what your looking for should always be in the last output type: message

#

my code is in python but hopefully this helps

orchid wadi
orchid wadi
#

@halcyon marsh thank you this helped!! had to use gpt to write this in JS but this was what i needed!!

even o3 with all the research kept saying that i dont need the container_id. i had to tell it very directly and copy and paste the documentation into the chat and say "No you're wrong" lol

#

Thank!

halcyon marsh
#

I literally went through this exact problem 2 days ago and had the same experience