FLUX.1 Kontext [pro]
Overview
FLUX.1 Kontext [pro] offers state-of-the-art editing capabilities with extra speed and fidelity. It maintains strong prompt adherence while executing region-level edits and scene-wide changes, with excellent character consistency and image semantics across iterations. No fine-tuning like LoRAs required.
FLUX.1 Kontext [pro] is hosted outside of DataCrunch infrastructure.
Below please find examples on how to use DataCrunch Inference API to generate images with FLUX.1 Kontext [pro].
Find out more about FLUX.1 Kontext.
Getting Started
Before generating images, make sure your account is ready to use the Inference API. Follow the Getting Started guide to create an account and top up your balance.
Authorization
To access and use these API endpoints, authorization is required. Please visit our Authorization page for detailed instructions on obtaining and using a bearer token for secure API access.
Generating images
Text to image
curl --request POST "https://relay.datacrunch.io/bfl/flux-kontext-pro" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <your_api_key>" \
--output "picture.png" \
--data '{
"prompt": "a scientist racoon eating icecream in a datacenter",
"steps": 50,
"guidance": 3.0,
"prompt_upsampling":true
}'import requests
import os
token = <your_api_key>
bearer_token = f"Bearer {token}"
url = "https://relay.datacrunch.io/bfl/flux-kontext-pro"
headers = {
"Content-Type": "application/json",
"Authorization": bearer_token
}
data = {
"prompt": "a scientist racoon eating icecream in a datacenter",
"steps": 50,
"guidance": 3.0,
"prompt_upsampling":True
}
resp = requests.post(url, headers=headers, json=data)
resp.raise_for_status()
ct = resp.headers.get("Content-Type", "")
outfile = "picture.png"
if ct.startswith("image/"):
with open(outfile, "wb") as f:
f.write(resp.content)
print(f"Saved raw image to {outfile}")const axios = require('axios');
const fs = require('fs');
const url = 'https://relay.datacrunch.io/bfl/flux-kontext-pro';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <your_api_key>'
};
const data = {
prompt: 'a scientist racoon eating icecream in a datacenter',
steps: 50,
guidance: 3.0,
prompt_upsampling: true
};
axios.post(url, data, {
headers,
responseType: 'arraybuffer'
})
.then(response => {
fs.writeFileSync('picture.png', response.data);
console.log('Saved image to picture.png');
})
.catch(error => {
console.error('Error:', error);
});Image to image
INPUT_BASE64="data:image/png;base64,$(base64 -i <your_picture>.png)"
read -r -d '' PAYLOAD <<EOF
{
"prompt": "Make the picture a pencil sketch",
"steps": 50,
"guidance": 2.0,
"input_image": "$INPUT_BASE64"
}
EOF
curl --request POST "https://relay.datacrunch.io/bfl/flux-kontext-pro" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <your_api_key>" \
--output "picture.png" \
--data "$PAYLOAD"import os
import requests
import base64
from PIL import Image
from io import BytesIO
token = <your_api_key>
bearer_token = f"Bearer {token}"
url = "https://relay.datacrunch.io/bfl/flux-kontext-pro"
headers = {
"Content-Type": "application/json",
"Authorization": bearer_token
}
image = Image.open("test_pic_small.png")
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode()
data = {
"prompt": "a scientist racoon eating icecream in a datacenter",
"steps": 50,
"guidance": 3.0,
'input_image': img_str,
}
resp = requests.post(url, headers=headers, json=data)
resp.raise_for_status()
ct = resp.headers.get("Content-Type", "")
outfile = "picture.png"
if ct.startswith("image/"):
with open(outfile, "wb") as f:
f.write(resp.content)
print(f"Saved raw image to {outfile}")const axios = require('axios');
const fs = require('fs');
const path = require('path');
const filePath = path.resolve(__dirname, 'test_pic_small.png');
const imageBuffer = fs.readFileSync(filePath);
const inputImage = `data:image/png;base64,${imageBuffer.toString('base64')}`;
const url = 'https://relay.datacrunch.io/bfl/flux-kontext-pro';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <your_api_key>'
};
const data = {
prompt: 'a scientist racoon eating icecream in a datacenter',
steps: 50,
guidance: 3.0,
input_image: inputImage
};
axios.post(url, data, {
headers,
responseType: 'arraybuffer'
})
.then(response => {
fs.writeFileSync('picture.png', response.data);
console.log('Saved image to picture.png');
})
.catch(error => {
console.error('Error:', error);
});Last updated
Was this helpful?