Skip to Content
API CallImage Generationblack-forest-labs/flux-kontext-pro/text-to-image

black-forest-labs/flux-kontext-pro/text-to-image API

This document introduces the input and output parameters of the black-forest-labs/flux-kontext-pro/text-to-image model call API for your reference when using the interface.


Request Parameters

Request Body

Field NameTypeRequiredDefaultDescription
promptstringRequired-Prompt words
modelstringRequired-The model name used for this request, here it is black-forest-labs/flux-kontext-pro/text-to-image.
nintOptional1Number of images to generate, range 1~4
aspect_ratiostringOptional”1:1”The aspect ratio of the image, formatted as “width:height”, e.g. “16:9” or “1:1”.
Supported sizes: “21:9”, “16:9”, “4:3”, “3:2”, “1:1”, “2:3”, “3:4”, “9:16”, “9:21”
seedintOptional-1Random seed to control the randomness of the model’s generated content. If you want the generated content to remain consistent, you can use the same seed parameter value.
stepsintOptional20Number of inferences, range 1~50
guidance_scalefloatOptional2.5The degree of consistency between the model output and the prompt, i.e., the degree of freedom of generated images; the larger the value, the smaller the model’s freedom, and the stronger the correlation with the user’s input prompts.
Range [1, 10].
negative_promptstringOptional-Negative prompt words for specifying content that should not appear in the generated image
response_formatstringOptional”url”Specifies the format of the generated image returned, default is url, optional b64_json

Response Parameters

Field NameTypeDescription
createdintegerUnix timestamp (in seconds) of when this request was created.
dataarrayInformation of the output image, including the download URL or Base64.
• When specifying the format of the generated image as url, the child field of the corresponding parameter is url;
• When specifying the format of the generated image as b64_json, the child field of the corresponding parameter is b64_json.
Note: The link will expire within 7 days after generation, please save the image promptly.
errorObjectError information object
error.codestringError code
error.messagestringError message
error.paramstringRequest id

Example

OPENAI Compatible Interface

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

Synchronous Request

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/text-to-image", "prompt": "Convert to quick pencil sketch", "aspect_ratio": "9:16" }'
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/text-to-image", prompt="Convert to quick pencil sketch", extra_body={ "aspect_ratio": "9:16" } ) print(response.data[0].url)

Response

{ "created": 1750667997, "data": [ { "url": "https://xxxxx/xxxx.png", "b64_json": "data:image/png;base64,{image_base64_string}" } ], "usage": { "input_tokens_details": {} } }
{ "error": { "message": "error_message", "type": "error_type", "param": "request_id", "code": "error_code" } }