Asked about Making a call

What is stop_reason and why check it?

An answer that works

It says why generation ended: finished naturally, hit the token limit, or requested a tool. Hitting the limit truncates the output without raising an exception, so without checking it you get silently incomplete data.

Reading an answer is not being able to give one. The section that teaches this is Making a call, 2 hours of The Messages API.

Learn this properly