# FLUX.1 Kontext \[max]

## Overview

FLUX.1 Kontext \[max] is the new premium model by Black Forest Labs. It brings maximum performance across all aspects – greatly improved prompt adherence and typography generation meet premium consistency for editing without compromise on speed.

FLUX.1 Kontext \[max] is hosted outside of Verda infrastructure.

Below please find examples on how to use Verda Inference API to generate images with FLUX.1 Kontext \[max].

Find out more about [FLUX.1 Kontext](https://bfl.ai/announcements/flux-1-kontext).

### **Getting Started**

Before generating images, make sure your account is ready to use the Inference API. Follow the [Getting Started](https://docs.verda.com/inference/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](https://docs.verda.com/inference/authorization) for detailed instructions on obtaining and using a bearer token for secure API access.

## Generating images

### Text to image

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request POST "https://relay.datacrunch.io/bfl/flux-kontext-max" \
--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
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import os

token = <your_api_key>
bearer_token = f"Bearer {token}"

url = "https://relay.datacrunch.io/bfl/flux-kontext-max"
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}")
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');
const fs = require('fs');

const url = 'https://relay.datacrunch.io/bfl/flux-kontext-max';
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);
  });
```

{% endtab %}
{% endtabs %}

### Image to image

{% tabs %}
{% tab title="cURL" %}

```bash
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-max" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <your_api_key>" \
--output "picture.png" \
--data "$PAYLOAD"
```

{% endtab %}

{% tab title="Python" %}

```python
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-max"
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}")
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
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-max';
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);
  });
```

{% endtab %}
{% endtabs %}
