In anthropic chat tracer:
elif type(chunk) is MessageStopEvent:
input_tokens = message.usage.input_tokens
output_tokens = message.usage.output_tokens
First the variable message is not set from chunk.message, and second MessageStopEvent does not have chunk.messages