Documentation Index
Fetch the complete documentation index at: https://docs.sunra.ai/llms.txt
Use this file to discover all available pages before exploring further.
In this guide, we’ll walk you through using one of our popular model endpoints, such as black-forest-labs/flux-kontext-pro/text-to-image.
Before diving in, ensure you have an API key from your dashboard,
which is required for authenticating your requests to the sunra API.
Choose your preferred programming language below to get started:
JavaScript/Node.js
To get started, install the client package and configure it with your API key:
npm install @sunra/client
Set your API key as an environment variable:
export SUNRA_KEY="your-api-key-here"
Once configured, you can invoke our Model API endpoint using the sunra client:
import { sunra } from "@sunra/client";
// Optionally, configure the client with a different API key other than the one set in the environment variable
sunra.config({
credentials: "YOUR_SUNRA_KEY",
});
const result = await sunra.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", {
input: {
prompt: "A rabbit wearing glasses reading a book under a mushroom in watercolor style.",
width: 1024,
height: 768,
output_format: "jpeg"
},
});
Python
Install the Python client library using pip:
Set your API key as an environment variable:
export SUNRA_KEY="your-api-key-here"
Configure and use the client:
import sunra_client
result = sunra_client.subscribe(
"black-forest-labs/flux-kontext-pro/text-to-image",
arguments={
"prompt": "A rabbit wearing glasses reading a book under a mushroom in watercolor style.",
"width": 1024,
"height": 768,
"output_format": "jpeg"
},
with_logs=True,
on_enqueue=print,
on_queue_update=print,
)
print(result)
Java
Add the Java client library to your project using your preferred build system:
implementation("ai.sunra.client:sunra-client:0.1.5")
Set your API key as an environment variable:
export SUNRA_KEY="your-api-key-here"
Configure and use the client:
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 rabbit wearing glasses reading a book under a mushroom in watercolor style.",
"width", 1024,
"height", 768,
"output_format", "jpeg"
);
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("black-forest-labs/flux-kontext-pro/text-to-image", options);
System.out.println("Completed!");
System.out.println(response.getData());
Next Steps
We offer various models like Flux kontext pro and Kling v2 master as ready-to-use APIs. Explore these on our Model Playground.
To use a model, visit its “API” tab to find the URL, source code, and usage examples, helping you integrate it seamlessly into your applications.
For more detailed information about each client library, visit our client libraries documentation.