The Java lib that’s too cool for bloated dependencies. Edits, fills, expands, generates, and low-key judges every other library still downloading 300 MB of JARs.
If other image libs were at a party, they'd still be figuring out Maven while Kontext4J already made your avatar a cyberpunk queen and found a mysterious nano banana in your pocket. 🍌💀
- Single-file, dependency-light Java wrapper for BFL/Flux Kontext APIs.
- Fluent AF:
new Kontext4J().init(key).generate(...).getUrl()
- Handles local files, remote URLs, and base64 like a pro.
- Polls until server says "Ready" — no email-refreshing required.
- Easter egg: sometimes gives you a nano banana. Nobody knows why.
edit(...)
— multi-image editing, masks, prompts, negative prompts, seeds, guidance… basically everything you want.fill(...)
— inpainting with optional masks and mask modes.generate(...)
— text → image, also supports reference images.expand(...)
— outpaint top/bottom/left/right like a boss.- Handles paths, URLs, base64 automatically.
- Polling included, waits for
status == Ready
. - Stores multiple result URLs. Use
getUrl()
,getUrls()
, ordownload(path)
. - Lightweight JSON parsing with
org.json
.
Other libs be like:
- “We need 300 MB of JARs and 12 XML files just to say hi.”
- Kontext4J: “Hold my beer 🍺, I’m done in one file.”
- “We spin 17 threads to make a 200ms request.”
- Kontext4J: single-threaded zen energy.
Copy Kontext4J.java
into your project (src/main/java/io/github/initio/kontext4j/Kontext4J.java
).
Dependencies:
- Java 11+
org.json:json
Maven snippet:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
</dependency>
Kontext4J k = new Kontext4J().init("YOUR_API_KEY_HERE");
// no api key? no magic. 💀
k.model("generate")
.generate(
"A tiny robot sipping coffee, cinematic lighting, ultra detailed",
null, "16:9", 42, 30, 7.5, null, null,
"png", null, null, 1, null, null, null
);
System.out.println("Image URL: " + k.getUrl());
// other libs would still be configuring XML, we already sipping coffee. ☕🤖
k.generateSimple("Cyberpunk cat in neon alley");
System.out.println(k.getUrl());
// because we don't need 300 MB of JARs for one cat. 🐱💡
k.edit(
"/home/me/pic1.jpg",
"/home/me/pic2.jpg",
null, null,
"Make all subjects wear futuristic helmets",
null, "1:1", 12345, 40, 6.0,
null, null, "jpg",
null, null, 2
);
System.out.println(k.getUrls());
// other libs: "please configure 12 XML files." 🤡
k.editSimple("/home/me/selfie.jpg", "Add sunglasses and party lights");
System.out.println(k.getUrl());
k.editMerge(List.of("/pic1.jpg","/pic2.jpg"), "Turn them into a superhero squad");
System.out.println(k.getUrls());
k.fill(
"/home/me/photo.jpg",
"/home/me/mask.png",
"replace",
"Make subject wear a futuristic helmet",
null, "1:1", 12345, 40, 6.0, null, null,
"jpg", null, null, 1
);
System.out.println(k.getUrls());
// inpainting so smooth, other libs cry into their 17 threads. 😭
k.expand(
"https://example.com/input.png",
200, 0, 0, 200,
"Extend environment to neon city skyline",
null, 40, 7.0, null, null, "png", null, null, 1
);
System.out.println(k.getUrl());
// other libs: "Wait… which edge is left again?" 🤔
k.download(Paths.get("kontext_result.png"));
// no fuss, no spaghetti code. 🍝
k.downloadIndex(Paths.get("kontext_result2.png"), 0);
init(String apiKey)
model(String modelName)
—"edit" | "fill" | "generate" | "expand"
setRequestTimeout(Duration d)
setPollIntervalMillis(long ms)
setMaxWaitMillis(long ms)
edit(...)
,editSimple(...)
,editMerge(...)
fill(...)
generate(...)
,generateSimple(...)
expand(...)
getUrls()
,getUrl()
,getLastRawResult()
download(Path)
,downloadIndex(Path, int)
Sometimes, very rarely, a URL or sample might contain a nano banana. No promises. Full giggle guaranteed when it shows up.
No result available
— forgotinit(apiKey)
?Polling timed out
— increasesetMaxWaitMillis(...)
or check webhook.Invalid JSON
— server sent a JSON-shaped potato 🥔.
MIT recommended. Free, petty, and small — like your nano banana.
(Memes > bug reports)
Kontext4J is tiny but opinionated: minimal dependencies, sane defaults, speed > drama. Use it to edit, generate, fill, expand — maybe find a nano banana too. 🍌