Troubleshooting file retrieval in OpenAI container API

Hi everyone,

I’m working on a Node/Express server that wraps OpenAI’s Assistants API using the @openai/agents package. My use case is a data‑migration bot: it uploads user spreadsheets, invokes the Code Interpreter tool to transform them, and then returns the generated Excel file to the user.

Starting with API v1.3, Code Interpreter files are exposed via the container API. The documentation says that each generated file is annotated with a container_file_citation containing a container_id and a file_id (e.g. cfile_xxxxx). To retrieve the file, you call openai.container.files.content(container_id, file_id)

My agent follows the structured output guidelines and returns:

{
  "status": "complete",
  "output_files": [
    {
      "file_id": "<value from annotation>",
      "filename": "gl_welfare_reconciliation_discrepancies.xlsx",
      "container_id": "<container ID>"
    }
  ],
  ...
}

This works fine when file_id looks like cfile_<alphanumeric>. However, about half the time the model instead returns a string like cfile:gl_welfare_reconciliation_discrepancies.xlsx. When I pass that into openai.container.files.content(), I get:

404 No such File object: cfile:gl_welfare_reconciliation_discrepancies.xlsx

Using openai.files.content() doesn’t help either, since /mnt/data/... isn’t a valid file ID. I’ve tried adding stronger instructions (“use the cfile_... ID from the container file citation, don’t return a filename”), but the issue persists intermittently.

Has anyone else run into these invalid cfile: identifiers? Is there a reliable way to map the returned filename back to the actual cfile_... ID, or to list files in the container and pick the right one? I saw that GET /v1/containers/{container_id}/files returns a list, but I’m not sure whether matching on filename is safe.

Any guidance or best practices for reliably retrieving Code Interpreter outputs via the API would be greatly appreciated!

Environment: Node 18, openai npm package v4.32.1, Assistants API (gpt-5 and code_interpreter tool), structured outputs enabled.