Call external API in wordpress based on user input

s is a reserved keyword, you cannot reuse the URL parameters and query variables used by WordPress itself. This issue is unrelated to the API request code.

Because your form has an input with the name s, the request is interpreted as a search request. As no posts were found in the WordPress search, you got a 404 response.

As a general rule of thumb, if a parameter is listed in the documentation as valid in a WP_Query post query object, it is unavailable for use in URLs.

Changing WordPress to allow s to be used would cripple a large portion of WordPress core functionality and require extensive internal modification of WordPress itself, as well as disabling all search related functionality, and any plugins that use similar systems, both on the frontend and in WP Admin.