BerriAI/litellm · error · Exception
Model needs to be set for bedrock
Error message
Model needs to be set for bedrock
What it means
The bedrock image route delegates to bedrock_image_generation.image_generation, which must build a signed boto3 request against a concrete Bedrock inference endpoint, so the model id (e.g. 'stability.sd3-large-v1:0', 'amazon.titan-image-generator-v1') is mandatory. As with other providers, litellm's dall-e-2 fallback only applies when neither model nor custom_llm_provider is given, so provider-without-model reaches this guard.
Solutions
- Use the provider-prefixed form: litellm.image_generation(model='bedrock/stability.sd3-large-v1:0', prompt='...') with AWS credentials in the environment.
- Or pass model='amazon.titan-image-generator-v2:0' together with custom_llm_provider='bedrock'.
- Check your proxy/Router yaml: every bedrock deployment needs a concrete model id, not just model_name.
Example fix
# before resp = litellm.image_generation(prompt="a cat", custom_llm_provider="bedrock") # Exception: Model needs to be set for bedrock # after resp = litellm.image_generation(model="bedrock/stability.sd3-large-v1:0", prompt="a cat")
Defensive patterns
Strategy: validation
Validate before calling
def call_bedrock_image(prompt: str, model: str | None = None):
model = model or "bedrock/stability.sd3-large-v1:0"
if not isinstance(model, str) or not model.strip():
raise ValueError("model is required for bedrock image generation (e.g. 'bedrock/stability.sd3-large-v1:0')")
return litellm.image_generation(model=model, prompt=prompt) Type guard
def is_bedrock_image_ready(model: str | None, custom_llm_provider: str | None) -> bool:
if custom_llm_provider == "bedrock":
return isinstance(model, str) and model.strip() != ""
return True Try / catch
try:
resp = litellm.image_generation(prompt=p, custom_llm_provider="bedrock")
except Exception as e:
if "Model needs to be set for bedrock" in str(e):
raise ValueError("set model='bedrock/<model-id>' and AWS credentials") from e
raise Prevention
- Always pass concrete Bedrock model ids (e.g. amazon.titan-image-generator-v2:0) in prefixed form.
- Lint proxy configs so bedrock deployments have non-empty model fields.
- Keep AWS credential checks alongside the model check in one pre-flight helper.
When it happens
Trigger: litellm.image_generation(prompt='...', custom_llm_provider='bedrock') with no model; proxy Router model entry with custom_llm_provider='bedrock' and an empty model field; passing model=None explicitly with the bedrock provider kwarg.
Common situations: AWS proxy config where model_name is set for routing but the actual Bedrock model id under litellm_params is blank; assuming env credentials (AWS_ACCESS_KEY_ID etc.) are enough and model is optional; migrating an azure/openai config and forgetting the model line.
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
- Bedrock guardrail failed
- completion_response must be of type ImageResponse for…
- Model needs to be set for black_forest_labs
- Batch record for /v1/completions is missing required…
- Batch record for /v1/responses is missing required `input`…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b9615d2fa30f1626.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/images/main.py:486
# Forward OpenAI organization if present (set by proxy pre-call utils)
organization: Final[str | None] = kwargs.get("organization", None)
model_response = openai_chat_completions.image_generation(
model=model,
prompt=prompt,
timeout=timeout,
api_key=api_key or dynamic_api_key,
api_base=api_base,
logging_obj=litellm_logging_obj,
optional_params=optional_params,
model_response=model_response,
organization=organization,
aimg_generation=aimg_generation,
client=client,
headers=headers,
)
elif custom_llm_provider == "bedrock":
if model is None:
raise Exception("Model needs to be set for bedrock")
model_response = bedrock_image_generation.image_generation(
model=model,
prompt=prompt,
timeout=timeout,
logging_obj=litellm_logging_obj,
optional_params=optional_params,
model_response=model_response,
aimg_generation=aimg_generation,
client=client,
api_base=api_base,
api_key=api_key,
)
elif custom_llm_provider in litellm._custom_providers: # Assume custom LLM provider
# Get the Custom Handler
custom_handler: CustomLLM | None = None
for item in litellm.custom_provider_map:
if item["provider"] == custom_llm_provider:
custom_handler = item["custom_handler"]View on GitHub (pinned to 77b7c6c40c)