# black-forest-labs/flux-kontext-max API

This document introduces the input and output parameters for invoking the `black-forest-labs/flux-kontext-max` model API, providing a reference for understanding the meaning of fields when using the interface.

---

## Request Parameters

### Request Body

| Field Name     | Type   | Required | Default | Description                                                                                                       |
| -------------- | ------ | -------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
| prompt         | string | Conditionally Required | -   | Prompt                                                                                                            |
| model          | string | Required | -      | The name of the model used for this request, which in this case is `black-forest-labs/flux-kontext-max`.         |
| image          | string | Required | -      | Base64 data or image link http://xxx                                                                             |
| n              | int    | Optional | 1      | Number of images to generate, with a range of 1~4                                                                 |
| strength       | float  | Optional | 0.8    | Degree to which the reference image is transformed, with a range of 0~1                                           |
| seed           | int    | Optional | -1     | Random seed for controlling the randomness of model generation. For consistent outputs, use the same seed value.  |
| steps          | int    | Optional | 20     | Number of inferences, with a range of 1~50                                                                       |
| guidance_scale | float  | Optional | 2.5    | The degree to which the model output conforms to the prompt, i.e., the freedom of image generation; the larger the value, the less freedom the model has, and the more closely it is related to the user's input prompt. [1, 10]. |
| negative_prompt| string | Optional | -      | Negative prompt for specifying content not desired in generated images                                            |
| response_format| string | Optional | "url"  | Specifies the format in which generated images are returned, default is `url`, can also be `b64_json`.            |

## Response Parameters

| Field Name      | Type      | Description                                                                                                                                                                         |
| --------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| created         | `integer` | Unix timestamp (seconds) when the request was created.                                                                                                                              |
| data            | `array`   | Information about output images, including image download URL or Base64.<br>• When the specified format for the generated image is URL, the subfield is URL;<br>• When the format is b64_json, the subfield is b64_json.<br>Note: The link will expire 7 days after generation, please make sure to save the image in a timely manner. |
| error           | `Object`  | Error message object                                                                                                                                                                 |
| error.code      | `string`  | Error code                                                                                                                                                                           |
| error.message   | `string`  | Error message                                                                                                                                                                        |
| error.param     | `string`  | Request id                                                                                                                                                                           |

## Example

### OPENAI Compatible Interface

`POST https://api.umodelverse.ai/v1/images/generations`

#### Synchronous Request

```bash
curl --location 'https://api.umodelverse.ai/v1/images/generations' \
--header "Authorization: Bearer $MODELVERSE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "model": "black-forest-labs/flux-kontext-max",
    "prompt": "Convert to quick pencil sketch",
    "image": "data:image/png;base64,{image_base64_string}"
}'
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url=os.getenv("BASE_URL", "https://api.umodelverse.ai/v1"),
    api_key=os.getenv("API_KEY", "$MODELVERSE_API_KEY")
)

response = client.images.generate(
    model="black-forest-labs/flux-kontext-max",
    prompt="Convert to quick pencil sketch",
    extra_body={
        "image": "data:image/png;base64,{image_base64_string}"
    }
)

print(response.data[0].url)
```

### Response

```json
{
  "created": 1750667997,
  "data": [
    {
      "url": "https://xxxxx/xxxx.png",
      "b64_json": "data:image/png;base64,{image_base64_string}"
    }
  ],
  "usage": {
    "input_tokens_details": {}
  }
}
```

```json
{
  "error": {
    "message": "error_message",
    "type": "error_type",
    "param": "request_id",
    "code": "error_code"
  }
}
```

<!--
TODO: Asynchronous Request
### Asynchronous Request

``` -->