Small issue first: The api key should be in header. It works in the body, too, but this is deprecated.
I am not sure why the searchable PDF generation fails. Looks all ok on first glance.
Have you tried to call the OCR API with Postman? Does it work there for you?
-
If yes, Postman can generate the OCR API Python code for you. ChatGPT can also generate good code for OCR.Space OCR API calls.
-
If no, please post a screenshot of the Postman error.