import ai.sunra.client.*;
import ai.sunra.client.queue.*;
import java.util.Map;
import com.google.gson.JsonObject;
import java.util.function.Consumer;
ClientConfig config = ClientConfig.builder()
.withCredentials(CredentialsResolver.fromEnv())
.build();
SunraClient client = SunraClient.withConfig(config);
Map<String, Object> input = Map.of(
"prompt", "A cute hamster lies leisurely on a lifebuoy, wearing fashionable sunglasses, and drifts with the gentle waves on the shimmering sea surface. The hamster reclines comfortably, enjoying a peaceful and pleasant time. Cartoon style, the camera follows the subject moving, with a heartwarming and high picture quality.",
"guidance_scale", 0.5,
"aspect_ratio", "16:9",
"duration", 5,
"start_image", "https://assets.sunra.ai/uploads/1748811753168-05ceab0d.png"
);
Consumer<QueueStatus.StatusUpdate> statusUpdateHandler = update -> {
String status = update.getStatus().toString();
String message = String.format("\nStatus Update: %s, Request ID: %s",
status, update.getRequestId());
System.out.println(message);
};
SubscribeOptions<JsonObject> options = SubscribeOptions.<JsonObject>builder()
.input(input)
.resultType(JsonObject.class)
.onQueueUpdate(statusUpdateHandler)
.logs(true)
.build();
Output<JsonObject> response = client.subscribe("kling/kling-v2-master/image-to-video", options);
System.out.println("Completed!");
System.out.println(response.getData());