Sunra manages endpoint requests through a queue system, ensuring reliability and scalability. Use the subscribe method to submit a request and await the result.Example:
Copy
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 dog running in the park");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();// save the subscribe request to a variable and print itOutput<JsonObject> response = client.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", options);System.out.println("Completed!");System.out.println(response.getData());