One last field, because ignoring it produces the most quietly broken output of all.
Stop reason
Also called stop_reason, Truncated output, max_tokens
A field on each response saying why the model stopped: it finished, hit your token limit, wants a tool run, or declined. It arrives on a success, so code that only reads the text can treat half an answer as a whole one.
An agent that saves a file from a cut-off response saves half a file, with status 200 and no error. Whatever drives a model has to check this field before it uses the content.
Say it to your agent
“Check response.stop_reason before using the content. On max_tokens, save nothing and retry with a higher limit. Add a test that feeds in a truncated response and asserts that no file gets written.”