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.');
}