BerriAI/litellm · error · Exception
Model needs to be set for black_forest_labs
Error message
Model needs to be set for black_forest_labs
What it means
The black_forest_labs (FLUX) image route requires an explicit model because it delegates to bfl_image_generation.image_generation, which needs the model name to pick the BFL API endpoint and polling behavior. litellm only auto-defaults model to 'dall-e-2'/openai when BOTH model and custom_llm_provider are None (litellm/images/main.py:224-232), so a provider set without a model reaches this guard as None.
Solutions
- Pass a BFL model, ideally provider-prefixed: litellm.image_generation(model='black_forest_labs/flux-pro-1.1', prompt='...') so both provider and model resolve from one string.
- If provider is passed separately, still supply model='flux-pro-1.1' (or flux-dev / flux-kontext variants).
- In proxy/Router config, verify the model entry has a concrete model value, not just model_name + custom_llm_provider.
Example fix
# before resp = litellm.image_generation(prompt="a cat", custom_llm_provider="black_forest_labs") # Exception: Model needs to be set for black_forest_labs # after resp = litellm.image_generation(model="black_forest_labs/flux-pro-1.1", prompt="a cat")
Defensive patterns
Strategy: validation
Validate before calling
def call_bfl(prompt: str, model: str | None = None):
model = model or "black_forest_labs/flux-pro-1.1"
if model is None or model.strip() == "":
raise ValueError("model is required for black_forest_labs image generation")
return litellm.image_generation(model=model, prompt=prompt) Type guard
def is_bfl_ready(model: str | None, custom_llm_provider: str | None) -> bool:
"""True when the call cannot hit the 'Model needs to be set' guard."""
if custom_llm_provider == "black_forest_labs":
return isinstance(model, str) and model.strip() != ""
return True Try / catch
try:
resp = litellm.image_generation(prompt=p, custom_llm_provider="black_forest_labs")
except Exception as e:
if "Model needs to be set for black_forest_labs" in str(e):
raise ValueError("pass model='black_forest_labs/flux-pro-1.1' (or another FLUX model)") from e
raise Prevention
- Standardize on provider-prefixed model strings ('black_forest_labs/flux-...') so the model can never be None.
- Validate proxy/Router model entries with a schema requiring a non-empty model field.
- Unit-test your image wrapper with None-model inputs to assert it fails fast with your own message.
When it happens
Trigger: litellm.image_generation(prompt='...', custom_llm_provider='black_forest_labs') with no model; a Router/proxy deployment whose model entry sets litellm_params.custom_llm_provider='black_forest_labs' but leaves model empty; passing model=None explicitly while relying on the provider kwarg.
Common situations: Proxy config yaml with a model_name but a missing/blank model field under litellm_params; copy-pasted chat-style invocations where the provider is a separate argument and the model string was omitted; assuming litellm defaults a model per provider.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- BFL error
- BFL initial request failed
- Error parsing BFL response
- Error parsing initial response
- Image generation failed
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/51ff9aeebde741a0.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/images/main.py:411
_api_base: Final = api_base or litellm.api_base
litellm_params_dict["api_base"] = _api_base
return llm_http_handler.image_generation_handler(
api_key=api_key,
model=model,
prompt=prompt,
image_generation_provider_config=image_generation_config,
image_generation_optional_request_params=optional_params,
custom_llm_provider=custom_llm_provider,
litellm_params=litellm_params_dict,
logging_obj=litellm_logging_obj,
timeout=timeout,
client=client,
)
elif custom_llm_provider == "black_forest_labs":
# Route to BFL-specific handler (polling required)
if model is None:
raise Exception("Model needs to be set for black_forest_labs")
return bfl_image_generation.image_generation(
model=model,
prompt=prompt,
model_response=model_response,
optional_params=optional_params,
litellm_params=litellm_params_dict,
logging_obj=litellm_logging_obj,
timeout=timeout,
extra_headers=extra_headers,
client=client,
aimg_generation=aimg_generation,
)
elif custom_llm_provider == "azure_ai":
from litellm.llms.azure_ai.common_utils import AzureFoundryModelInfo
api_base = AzureFoundryModelInfo.get_api_base(api_base)
api_key = AzureFoundryModelInfo.get_api_key(api_key)
if extra_headers is not None:View on GitHub (pinned to 77b7c6c40c)