500 Error, Get custom field and returning it

500 error or internal server error is probably caused by a PHP error.
By enabling WordPress debug, you’ll easily find where the problem is.
You can follow the instructions here https://wordpress.org/support/article/debugging-in-wordpress/#wp_debug_log

From your code, it’s easy, you’re missing a semi-column before the closing curly bracket.