For requests that may take a long time, consider using a callback mechanism.
Generate a unique identifier for the request (e.g., UUIDv4) and store it (e.g., in a database) along with a mapping to the file you're downloading from the other endpoint.
Return a callback URL to the client that includes this unique ID.
The client can then poll the callback URL to check if the file is ready.
If the client checks too early, return a response indicating that the file is not ready yet.
If the client never accesses the callback URL, make sure to implement a cleanup mechanism to remove unused data.