Based on the API doc , if the purpose is “user_data“ the expiry_after param is not recognized. Dropping that parameter files get uploaded for usage in downstream LLM invocations. Perhaps a recent regression ?
from openai import OpenAIclient = OpenAI()
client.files.create(file=open(“mydata.jsonl”, “rb”),purpose=“user_data” expires_after={“anchor”: “created_at”,“seconds”: 3600})
Perhaps you missed a comma after “user_data”.
Just tried it now (openai 1.101.0) and it looks fine.
Actually, it is nice to see it is properly working, by 2025-08-09 it was working only 1 out of 10 times and that parameter didn’t exist yet (had to use extra_body).
from datetime import datetime
fileobject = client.files.create(
file = your_file,
purpose="user_data",
expires_after= {
"seconds": 3600,
"anchor": "created_at"
}
)
print('Expires at: ',str(datetime.fromtimestamp(fileobject.expires_at)), "Now is: ", datetime.now())
fileobject.model_dump()
nope the code example in the API doc is missing the comma.
Exception : { “detail”: “Files.create() got an unexpected keyword argument ‘expires_after’” }
openai client version : 1.70 and
I see, you are correct. There is a typo in the docs.
Other than that, I’m happy to see we can set an expiration for files!
agreed, it is useful for setting user expectations on specific use case - RAG knowledge bot Q&A vs generic Q&A with or w/o user uploaded file.
I see. Don’t forget to update your packages, this change is very recent.
pip install --upgrade openai
Thank you that was it! I wish the docs are updated to state minimum package requirements