Skill: gamaleldientarek/black-forest-labs-flux (version 0.1.0)

--- name: black-forest-labs-flux description: Generate images with Black Forest Labs FLUX models using a direct BFL API key. Use when the user wants FLUX image generation through Black Forest Labs itself (not fal.ai), already has a BFL API key, or specifically mentions Black Forest Labs, BFL, flux-2-pro-preview, flux-pro, flux-dev, or flux-kontext models. --- # Black Forest Labs FLUX Generate images through **Black Forest Labs' direct API** using the bundled script in `scripts/bfl-generate.sh`. ## Quick start 1. Ensure `BFL_API_KEY` is available in the environment or in `/root/.clawdbot/.env`. 2. Run: ```bash /root/clawd/skills/black-forest-labs-flux/scripts/bfl-generate.sh "your prompt here" [output-file] ``` Example: ```bash /root/clawd/skills/black-forest-labs-flux/scripts/bfl-generate.sh \ "A cinematic scene of a monkey sitting proudly on top of a red Ferrari sports car" \ /root/clawd/output/monkey-ferrari.jpg ``` The script prints the saved file path on success. ## When to use this skill Use this skill when: - The user has a **Black Forest Labs API key** - The user wants **direct FLUX generation** instead of fal.ai or another wrapper - The user mentions **BFL**, **Black Forest Labs**, or direct FLUX model endpoints Do **not** use this skill for: - fal.ai keys (`FAL_KEY`) — use built-in fal support instead - OpenAI image generation - Google Gemini image generation ## Default behavior The script defaults to: - model: `flux-2-pro-preview` - width: `1536` - height: `1024` Override these with environment variables before running: ```bash export BFL_MODEL=flux-pro export BFL_WIDTH=1024 export BFL_HEIGHT=1024 ``` Then call the script normally. ## How it works The BFL API is asynchronous: 1. Submit a generation request 2. Capture `polling_url` 3. Poll until status becomes `Ready` 4. Download the returned image URL The bundled script already handles this flow. ## Troubleshooting - If the script says `BFL_API_KEY not set`, add the key to the environment first. - If generation fails, inspect the JSON returned by the API; the script prints it to stderr. - If the request succeeds but takes longer than expected, re-run with a simpler prompt or smaller dimensions. ## scripts/ - `scripts/bfl-generate.sh` — direct Black Forest Labs FLUX generation via API

path: scripts/bfl-generate.sh
content: #!/usr/bin/env bash
set -euo pipefail

if [[ -f /root/.clawdbot/.env ]]; then
  # shellcheck disable=SC1091
  source /root/.clawdbot/.env
fi

if [[ -z "${BFL_API_KEY:-}" ]]; then
  echo "Error: BFL_API_KEY not set" >&2
  exit 1
fi

PROMPT="${1:-}"
OUTFILE="${2:-/root/clawd/output/bfl-image-$(date +%s).jpg}"
MODEL="${BFL_MODEL:-flux-2-pro-preview}"
WIDTH="${BFL_WIDTH:-1536}"
HEIGHT="${BFL_HEIGHT:-1024}"

if [[ -z "$PROMPT" ]]; then
  echo "Usage: $0 \"prompt\" [outfile]" >&2
  exit 1
fi

mkdir -p "$(dirname "$OUTFILE")"

PAYLOAD=$(python3 - "$PROMPT" "$WIDTH" "$HEIGHT" <<'PY'
import json, sys
prompt, width, height = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
print(json.dumps({"prompt": prompt, "width": width, "height": height}))
PY
)

REQUEST_JSON=$(curl -sS -X POST "https://api.bfl.ai/v1/${MODEL}" \
  -H 'accept: application/json' \
  -H "x-key: ${BFL_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d "$PAYLOAD")

POLLING_URL=$(python3 - "$REQUEST_JSON" <<'PY'
import json,sys
obj=json.loads(sys.argv[1])
print(obj.get('polling_url',''))
PY
)
REQUEST_ID=$(python3 - "$REQUEST_JSON" <<'PY'
import json,sys
obj=json.loads(sys.argv[1])
print(obj.get('id',''))
PY
)

if [[ -z "$POLLING_URL" ]]; then
  echo "BFL request failed:" >&2
  echo "$REQUEST_JSON" >&2
  exit 1
fi

echo "Request ID: $REQUEST_ID" >&2

for _ in $(seq 1 240); do
  sleep 1
  RESULT_JSON=$(curl -sS -X GET "$POLLING_URL" \
    -H 'accept: application/json' \
    -H "x-key: ${BFL_API_KEY}")
  STATUS=$(python3 - "$RESULT_JSON" <<'PY'
import json,sys
obj=json.loads(sys.argv[1])
print(obj.get('status',''))
PY
)
  if [[ "$STATUS" == "Ready" ]]; then
    IMAGE_URL=$(python3 - "$RESULT_JSON" <<'PY'
import json,sys
obj=json.loads(sys.argv[1])
res=obj.get('result',{})
print(res.get('sample') or res.get('image') or '')
PY
)
    if [[ -z "$IMAGE_URL" ]]; then
      echo "BFL returned Ready but no image URL:" >&2
      echo "$RESULT_JSON" >&2
      exit 1
    fi
    curl -sS "$IMAGE_URL" -o "$OUTFILE"
    echo "$OUTFILE"
    exit 0
  elif [[ "$STATUS" == "Error" || "$STATUS" == "Failed" || "$STATUS" == "Content Moderated" ]]; then
    echo "Generation failed:" >&2
    echo "$RESULT_JSON" >&2
    exit 1
  fi
done

echo "Timed out waiting for BFL result" >&2
exit 1


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)