BerriAI/litellm · error · ValueError
RECRAFT_API_KEY is not set
Error message
RECRAFT_API_KEY is not set
What it means
Credential guard in the Recraft image-generation config's validate_environment: no key resolved from the argument or RECRAFT_API_KEY secret, so the generation request cannot be authenticated and fails validation before any HTTP call.
Source
Thrown at litellm/llms/recraft/image_generation/transformation.py:87
complete_url: str = api_base or get_secret_str("RECRAFT_API_BASE") or self.DEFAULT_BASE_URL
complete_url = complete_url.rstrip("/")
complete_url = f"{complete_url}/{self.IMAGE_GENERATION_ENDPOINT}"
return complete_url
def validate_environment(
self,
headers: dict,
model: str,
messages: list[AllMessageValues],
optional_params: dict,
litellm_params: dict,
api_key: str | None = None,
api_base: str | None = None,
) -> dict:
final_api_key: Final[str | None] = api_key or get_secret_str("RECRAFT_API_KEY")
if not final_api_key:
raise ValueError("RECRAFT_API_KEY is not set")
headers["Authorization"] = f"Bearer {final_api_key}"
return headers
def transform_image_generation_request(
self,
model: str,
prompt: str,
optional_params: dict,
litellm_params: dict,
headers: dict,
) -> dict:
"""
Transform the image generation request to the recraft image generation request body
https://www.recraft.ai/docs#generate-image
"""
recratft_image_generation_request_body: Final[RecraftImageGenerationRequestParams] = (View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set the RECRAFT_API_KEY environment variable.
- Or pass api_key to the image generation call.
Example fix
litellm.image_generation(model="recraft/...", api_key="<key>", prompt=...)
Defensive patterns
Strategy: validation
When it happens
Trigger: Triggered when calling Recraft image generation without RECRAFT_API_KEY set in the environment or passed as api_key.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/8429739d3313fe64.
Report an issue: GitHub.