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

This document introduces the input and output parameters for calling the `black-forest-labs/flux-kontext-pro` model API, allowing you to refer to the field meanings when using the interface.

---

## Request Parameters

### Request Body

| Field Name     | Type   | Required | Default | Description                                                                                                                   |
| -------------- | ------ | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------- |
| prompt         | string | Conditional Required | -      | Prompt                                                                                                                        |
| model          | string | Required | -      | The model name used for this request, which is `black-forest-labs/flux-kontext-pro`.                                          |
| image          | string | Required | -      | Base64 data or image link http://xxx                                                                                          |
| n              | int    | Optional | 1       | Number of generated images, the range is 1~4                                                                                  |
| strength       | float  | Optional | 0.8     | Degree of reference to the transformed image, the range is 0~1                                                                |
| seed           | int    | Optional | -1      | Random seed used to control the randomness of the model's output. If you want the output to be consistent, use the same seed parameter value.                          |
| steps          | int    | Optional | 20      | Number of inference steps, the range is 1~50                                                                                 |
| guidance_scale | float  | Optional | 2.5     | Degree of consistency between the model's output and the prompt, or the degree of freedom in generated images; the larger the value, the less freedom the model has, and the stronger the relevance with the user's input prompt. <br>Value range [1, 20]. |
| negative_prompt | string | Optional | -      | Negative prompt, used to specify content you don't want to appear in the generated image                                       |
| response_format | string | Optional | "url"  | Specifies the format to return the generated image, default is `url`, optional `b64_json`                                      |

## Response Parameters

| Field Name    | Type     | Description                                                                                                                                                                                                                      |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| created       | `integer` | The Unix timestamp (seconds) for when the request was created.                                                                                                                                                                               |
| data          | `array`   | Information about the output image, including the image download URL or Base64. <br>• When the specified format is url, the subfield is url; <br>• When the specified format is b64_json, the subfield is b64_json. <br>Note: The link will expire within 7 days after generation, please be sure to save the image in time. |
| error         | `Object`  | Error information 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-pro",
    "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-pro",
    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

``` -->