Hello Mattia,
Your code snippet is not importing the PHP classes in the right way. It should be something like this:
use Agence104\LiveKit\EgressServiceClient;
use Agence104\LiveKit\EncodedOutputs;
use Livekit\EncodedFileOutput;
use Livekit\S3Upload;
...
// Use the EgressServiceClient to start a recording
$egressClient = new EgressServiceClient($LIVEKIT_URL, $LIVEKIT_API_KEY, $LIVEKIT_API_SECRET);
// Define an S3Upload
$s3Upload = new S3Upload();
$s3Upload->setEndpoint($_ENV["S3_ENDPOINT"]);
$s3Upload->setAccessKey($_ENV["S3_ACCESS_KEY"]);
$s3Upload->setSecret($_ENV["S3_SECRET_KEY"]);
$s3Upload->setBucket("openvidu");
// Define an EncodedFileOutput
$output = new EncodedFileOutput();
$output->setS3($s3Upload);
// Define the EncodedOutputs
$encodedOutputs = new EncodedOutputs();
$encodedOutputs->setFile($output);
// Perform the request to start the egress
$egressResponse = $egressClient->startRoomCompositeEgress($roomName, "grid", $encodedOutputs);
Notice that some classes are the ones generated automatically by the livekit protocol (with protobuf), and they should be imported from Livekit\ package directly, not from Agence104\LiveKit\. IMHO, using an IDE with a good autocomplete system or even an AI copilot can help you overcome this little details very easily.
Best regards!