Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

fix/blackboxai-models (#412)

Thomas Hebrard7d064de473c8
diff --git a/.pipelex/inference/backends/blackboxai.toml b/.pipelex/inference/backends/blackboxai.toml
index 916603304..aa175ef40 100644
--- a/.pipelex/inference/backends/blackboxai.toml
+++ b/.pipelex/inference/backends/blackboxai.toml
@@ -11,9 +11,6 @@
# - Headers with dots must be quoted (e.g., ["gpt-4.5-preview"])
# - Model costs are in USD per million tokens (input/output)
#
-# Documentation: https://docs.pipelex.com
-# Support: https://go.pipelex.com/discord
-#
################################################################################
################################################################################
@@ -78,12 +75,18 @@ inputs = ["text", "images"]
outputs = ["text", "structured"]
costs = { input = 15.00, output = 75.00 }
-[claude-sonnet-4]
+[claude-4-sonnet]
model_id = "blackboxai/anthropic/claude-sonnet-4"
inputs = ["text", "images"]
outputs = ["text", "structured"]
costs = { input = 3.00, output = 15.00 }
+["claude-4.5-sonnet"]
+model_id = "blackboxai/anthropic/claude-sonnet-4.5"
+inputs = ["text", "images"]
+outputs = ["text", "structured"]
+costs = { input = 0.28, output = 1.10 }
+
# --- Google Models ------------------------------------------------------------
["gemini-2.5-flash"]
model_id = "blackboxai/google/gemini-2.5-flash"
@@ -179,3 +182,47 @@ inputs = ["text"]
outputs = ["text", "structured"]
costs = { input = 0.00, output = 0.00 }
+
+################################################################################
+# IMAGE GENERATION MODELS
+################################################################################
+
+[flux-pro]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/black-forest-labs/flux-pro"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.04 }
+
+["flux-pro/v1.1"]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/black-forest-labs/flux-1.1-pro"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.04 }
+
+["flux-pro/v1.1-ultra"]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/black-forest-labs/flux-1.1-pro-ultra"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.06 }
+
+["fast-lightning-sdxl"]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/bytedance/sdxl-lightning-4step"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.0014 }
+
+[nano-banana]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/google/nano-banana"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.039 }
diff --git a/.pipelex/inference/deck/base_deck.toml b/.pipelex/inference/deck/base_deck.toml
index ff09ecf6d..d09365709 100644
--- a/.pipelex/inference/deck/base_deck.toml
+++ b/.pipelex/inference/deck/base_deck.toml
@@ -46,8 +46,8 @@ smart_llm = [
llm_for_large_codebase = ["gemini-2.5-pro", "claude-4.5-sonnet", "gpt-5"]
# Image generation aliases
-base-img-gen = "flux-pro/v1.1"
-best-img-gen = "flux-pro/v1.1-ultra"
+base-img-gen = "flux-pro/v1.1-ultra"
+best-img-gen = "nano-banana"
fast-img-gen = "fast-lightning-sdxl"
####################################################################################################
diff --git a/.pipelex/inference/routing_profiles.toml b/.pipelex/inference/routing_profiles.toml
index e35566fef..4a77d257d 100644
--- a/.pipelex/inference/routing_profiles.toml
+++ b/.pipelex/inference/routing_profiles.toml
@@ -35,11 +35,16 @@ default = "pipelex_inference"
"claude-*" = "pipelex_inference"
"grok-*" = "pipelex_inference"
"gemini-*" = "pipelex_inference"
-"*-sdxl" = "fal"
-"flux-*" = "fal"
+"*-sdxl" = "blackboxai"
+"flux-*" = "blackboxai"
+"nano-banana" = "blackboxai"
"gpt-image-1" = "openai"
"mistral-ocr" = "mistral"
+[profiles.all_blackboxai]
+description = "Use BlackBoxAI backend for all its supported models"
+default = "blackboxai"
+
[profiles.all_bedrock]
description = "Use Bedrock backend for all its supported models"
default = "bedrock"
diff --git a/pipelex/cogt/img_gen/img_gen_job_components.py b/pipelex/cogt/img_gen/img_gen_job_components.py
index 5615a55d8..4ac46e569 100644
--- a/pipelex/cogt/img_gen/img_gen_job_components.py
+++ b/pipelex/cogt/img_gen/img_gen_job_components.py
@@ -46,7 +46,7 @@ class ImgGenJobParams(BaseModel):
safety_tolerance: int | None = Field(default=None, ge=1, le=6)
is_raw: bool
output_format: OutputFormat = Field(strict=False)
- seed: int | None = Field(None, ge=0)
+ seed: int | None = Field(default=None, ge=0)
class ImgGenJobParamsDefaults(ConfigModel):
diff --git a/pipelex/cogt/img_gen/img_gen_worker_factory.py b/pipelex/cogt/img_gen/img_gen_worker_factory.py
index fbe0199fe..5d0073c44 100644
--- a/pipelex/cogt/img_gen/img_gen_worker_factory.py
+++ b/pipelex/cogt/img_gen/img_gen_worker_factory.py
@@ -70,6 +70,23 @@ class ImgGenWorkerFactory:
inference_model=inference_model,
reporting_delegate=reporting_delegate,
)
+ case "openai_alt_img_gen":
+ from pipelex.plugins.openai.openai_factory import OpenAIFactory # noqa: PLC0415
+ from pipelex.plugins.openai.openai_img_gen_alt_worker import OpenAIImgGenAlternativeWorker # noqa: PLC0415
+
+ img_gen_sdk_instance = plugin_sdk_registry.get_sdk_instance(plugin=plugin) or plugin_sdk_registry.set_sdk_instance(
+ plugin=plugin,
+ sdk_instance=OpenAIFactory.make_openai_client(
+ plugin=plugin,
+ backend=backend,
+ ),
+ )
+
+ img_gen_worker = OpenAIImgGenAlternativeWorker(
+ sdk_instance=img_gen_sdk_instance,
+ inference_model=inference_model,
+ reporting_delegate=reporting_delegate,
+ )
case _:
msg = f"Plugin '{plugin}' is not supported for image generation"
raise NotImplementedError(msg)
diff --git a/pipelex/kit/configs/inference/backends/blackboxai.toml b/pipelex/kit/configs/inference/backends/blackboxai.toml
index 916603304..92c4a1ffe 100644
--- a/pipelex/kit/configs/inference/backends/blackboxai.toml
+++ b/pipelex/kit/configs/inference/backends/blackboxai.toml
@@ -179,3 +179,47 @@ inputs = ["text"]
outputs = ["text", "structured"]
costs = { input = 0.00, output = 0.00 }
+
+################################################################################
+# IMAGE GENERATION MODELS
+################################################################################
+
+[flux-pro]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/black-forest-labs/flux-pro"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.04 }
+
+["flux-pro/v1.1"]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/black-forest-labs/flux-1.1-pro"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.04 }
+
+["flux-pro/v1.1-ultra"]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/black-forest-labs/flux-1.1-pro-ultra"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.06 }
+
+["fast-lightning-sdxl"]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/bytedance/sdxl-lightning-4step"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.0014 }
+
+[nano-banana]
+model_type = "img_gen"
+sdk = "openai_alt_img_gen"
+model_id = "blackboxai/google/nano-banana"
+inputs = ["text"]
+outputs = ["image"]
+costs = { input = 0.0, output = 0.039 }
diff --git a/pipelex/kit/configs/inference/routing_profiles.toml b/pipelex/kit/configs/inference/routing_profiles.toml
index e35566fef..a5c5a0ce4 100644
--- a/pipelex/kit/configs/inference/routing_profiles.toml
+++ b/pipelex/kit/configs/inference/routing_profiles.toml
@@ -29,14 +29,19 @@ active = "pipelex_first"
description = "Use Pipelex Inference backend for all its supported models"
default = "pipelex_inference"
+[profiles.all_blackboxai]
+description = "Use BlackBoxAI backend for all its supported models"
+default = "blackboxai"
+
[profiles.pipelex_first.routes]
# Pattern matching: "model-pattern" = "backend-name"
"gpt-*" = "pipelex_inference"
"claude-*" = "pipelex_inference"
"grok-*" = "pipelex_inference"
"gemini-*" = "pipelex_inference"
-"*-sdxl" = "fal"
-"flux-*" = "fal"
+"*-sdxl" = "blackboxai"
+"flux-*" = "blackboxai"
+"nano-banana" = "blackboxai"
"gpt-image-1" = "openai"
"mistral-ocr" = "mistral"
diff --git a/pipelex/plugins/openai/openai_factory.py b/pipelex/plugins/openai/openai_factory.py
index c40ffcab0..fccc3265f 100644
--- a/pipelex/plugins/openai/openai_factory.py
+++ b/pipelex/plugins/openai/openai_factory.py
@@ -28,6 +28,7 @@ class OpenAIFactoryError(CogtError):
class OpenAISdkVariant(StrEnum):
AZURE_OPENAI = "azure_openai"
OPENAI = "openai"
+ OPENAI_ALT_IMG_GEN = "openai_alt_img_gen"
class AzureExtraField(StrEnum):
@@ -66,6 +67,12 @@ class OpenAIFactory:
api_key=backend.api_key,
base_url=backend.endpoint,
)
+ case OpenAISdkVariant.OPENAI_ALT_IMG_GEN:
+ log.verbose(f"Making AsyncOpenAI client with endpoint: {backend.endpoint}")
+ the_client = openai.AsyncOpenAI(
+ api_key=backend.api_key,
+ base_url=backend.endpoint,
+ )
return the_client
diff --git a/pipelex/plugins/openai/openai_img_gen_alt_worker.py b/pipelex/plugins/openai/openai_img_gen_alt_worker.py
new file mode 100644
index 000000000..f68a66f71
--- /dev/null
+++ b/pipelex/plugins/openai/openai_img_gen_alt_worker.py
@@ -0,0 +1,81 @@
+import random
+from typing import TYPE_CHECKING, Any
+
+import openai
+from openai import APIConnectionError, BadRequestError, NotFoundError
+from typing_extensions import override
+
+from pipelex import log
+from pipelex.cogt.exceptions import LLMCompletionError, LLMModelNotFoundError, SdkTypeError
+from pipelex.cogt.image.generated_image import GeneratedImage
+from pipelex.cogt.img_gen.img_gen_job import ImgGenJob
+from pipelex.cogt.img_gen.img_gen_worker_abstract import ImgGenWorkerAbstract
+from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
+from pipelex.reporting.reporting_protocol import ReportingProtocol
+
+if TYPE_CHECKING:
+ from openai.types.chat import ChatCompletionMessage
+
+
+class OpenAIImgGenAlternativeWorker(ImgGenWorkerAbstract):
+ def __init__(
+ self,
+ sdk_instance: Any,
+ inference_model: InferenceModelSpec,
+ reporting_delegate: ReportingProtocol | None = None,
+ ):
+ super().__init__(inference_model=inference_model, reporting_delegate=reporting_delegate)
+
+ if not isinstance(sdk_instance, openai.AsyncOpenAI):
+ msg = f"Provided ImgGen sdk_instance is not of type openai.AsyncOpenAI: it's a '{type(sdk_instance)}'"
+ raise SdkTypeError(msg)
+
+ self.openai_client = sdk_instance
+
+ @override
+ async def _gen_image(
+ self,
+ img_gen_job: ImgGenJob,
+ ) -> GeneratedImage:
+ log.debug(f"Generating image with model: {self.inference_model.tag}")
+ img_gen_prompt_text = img_gen_job.img_gen_prompt.positive_text
+ messages = [{"role": "user", "content": img_gen_prompt_text}]
+ seed = img_gen_job.job_params.seed or random.randint(0, 2**32 - 1)
+ try:
+ response = await self.openai_client.chat.completions.create(
+ model=self.inference_model.model_id,
+ messages=messages, # type: ignore[arg-type]
+ seed=seed,
+ )
+ except NotFoundError as not_found_error:
+ # TODO: record llm config so it can be displayed here
+ msg = f"OpenAI model or deployment not found:\n{self.inference_model.desc}\nmodel: {self.inference_model.desc}\n{not_found_error}"
+ raise LLMModelNotFoundError(msg) from not_found_error
+ except APIConnectionError as api_connection_error:
+ msg = f"OpenAI API connection error: {api_connection_error}"
+ raise LLMCompletionError(msg) from api_connection_error
+ except BadRequestError as bad_request_error:
+ msg = f"OpenAI bad request error with model: {self.inference_model.desc}:\n{bad_request_error}"
+ raise LLMCompletionError(msg) from bad_request_error
+
+ openai_message: ChatCompletionMessage = response.choices[0].message
+ response_text = openai_message.content
+ if response_text is None:
+ msg = f"OpenAI response message content is None: {response}\nmodel: {self.inference_model.desc}"
+ raise LLMCompletionError(msg)
+ return GeneratedImage(
+ url=response_text,
+ width=1024,
+ height=1024,
+ )
+
+ @override
+ async def _gen_image_list(
+ self,
+ img_gen_job: ImgGenJob,
+ nb_images: int,
+ ) -> list[GeneratedImage]:
+ if nb_images > 1:
+ msg = f"The image genration backend '{self.inference_model.desc}' can't generate multiple images at once: {nb_images}"
+ raise NotImplementedError(msg)
+ return [await self._gen_image(img_gen_job=img_gen_job)]
diff --git a/pyproject.toml b/pyproject.toml
index c1ffc4f00..b605591d4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -329,6 +329,8 @@ ignore = [
"S106", # Possible hardcoded password assigned to argument: "secret"
"S105", # Possible hardcoded password assigned to: "child_secret"
+ "S311", # Cryptographically weak pseudo-random number generator
+
"TD002", # Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
"TD003", # Missing issue link for this TODO
diff --git a/tests/integration/pipelex/conftest.py b/tests/integration/pipelex/conftest.py
index 2d2aaf225..6653099a2 100644
--- a/tests/integration/pipelex/conftest.py
+++ b/tests/integration/pipelex/conftest.py
@@ -195,8 +195,10 @@ def llm_job_params(request: pytest.FixtureRequest) -> LLMJobParams:
# "flux-pro",
"flux-pro/v1.1",
# "flux-pro/v1.1-ultra",
- "fast-lightning-sdxl",
- "gpt-image-1",
+ # "fast-lightning-sdxl",
+ # "gpt-image-1",
+ # "nano-banana",
+ # "best-img-gen",
],
)
def img_gen_handle(request: pytest.FixtureRequest) -> str: