Skip to main content

Flux Kontext

Basic API Configuration

Base URL: https://api.foxaihub.com/api/v2

Headers Parameters:

{
"api-key": "Your API Key",
}
warning

The parameter is api-key instead of api_key.

Notes

The images generated by this API will only be saved for 24 hours, after which they will be deleted by the system. At that time, you will not be able to access the image via the URL.

Flux-Kontext Task

Path: /flux-kontext/pro/generate or /flux-kontext/max/generate

Method: POST

Type: application/json

Model Options:

  • pro: Standard model - $0.025 per generation
  • max: Premium model with enhanced quality - $0.05 per generation (double price)

Parameters:

Parameter NameTypeDescriptionRemarks
promptStringText description of the image processing taskRequired. The prompt should describe the desired image processing in detail
input_imageStringInput image for processingRequired. Can be either a base64 encoded image (with data URL prefix like data:image/jpeg;base64,{base64_data}) or an HTTP URL to an image. Base64 image size must not exceed 10MiB
aspect_ratioStringOutput image aspect ratioOptional. Options: "match_input_image", "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "4:5", "5:4", "21:9", "9:21", "2:1", "1:2". Default: "match_input_image"
seedIntegerRandom seed for reproducible resultsOptional. Use the same seed to get consistent outputs

Example Request:

POST /flux-kontext/pro/generate HTTP/1.1
Content-Type: application/json
api-key: your_api_key_here

{
"prompt": "Restore and colorize this image. Remove any scratches or imperfections",
"input_image": "https://cdn2.foxai.me/flux-kontext-12/Tesla.JPG"
}

Example Request with Base64 Image:

POST /flux-kontext/pro/generate HTTP/1.1
Content-Type: application/json
api-key: your_api_key_here

{
"prompt": "Restore and colorize this image. Remove any scratches or imperfections",
"input_image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj..."
}

Example Request with Base64 Image:

POST /flux-kontext/pro/generate HTTP/1.1
Content-Type: application/json
api-key: your_api_key_here

{
"prompt": "Restore and colorize this image. Remove any scratches or imperfections",
"input_image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj..."
}

Example Response:

{
"id": "f3hfma0ppnrm80cq6r8rhawj0w",
"error": null,
"created_at": "2025-06-03T13:52:59.061Z",
"output": "https://cdn2.foxai.me/flux-kontext-11/f3hfma0ppnrm80cq6r8rhawj0w.png"
}

Example Python Code:

import requests
import base64
import json
import os

def create_flux_kontext_task(image_path="Tesla.JPG", prompt="Restore and colorize this image. Remove any scratches or imperfections"):
"""
Create a flux-kontext task using local image file encoded as base64

Args:
image_path (str): Path to the image file (default: "Tesla.JPG")
prompt (str): The prompt for image processing

Returns:
dict: API response
"""
base_url = "https://api.foxaihub.com/api/v2"
api_key = "your api key"

# Check if image file exists
if not os.path.exists(image_path):
raise FileNotFoundError(f"Image file not found: {image_path}")

# Read and encode image as base64
with open(image_path, "rb") as image_file:
image_data = base64.b64encode(image_file.read()).decode('utf-8')
# Add data URL prefix for base64 image
base64_image = f"data:image/jpeg;base64,{image_data}"

# Prepare request
url = f"{base_url}/flux-kontext/pro/generate"
headers = {
"Content-Type": "application/json",
"api-key": api_key
}

payload = {
"prompt": prompt,
"input_image": base64_image
}

# Make request
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
if hasattr(e.response, 'text'):
print(f"Response: {e.response.text}")
raise

if __name__ == "__main__":
# Example usage
try:
result = create_flux_kontext_task()
print("Task created successfully:")
print(json.dumps(result, indent=2))
except Exception as e:
print(f"Error: {e}")