BerriAI/litellm · error · ValueError
COMETAPI_KEY or COMETAPI_API_KEY is not set
Error message
COMETAPI_KEY or COMETAPI_API_KEY is not set
What it means
Credential guard in the CometAPI image-generation config: neither an explicit api_key nor the COMETAPI_KEY/COMETAPI_API_KEY secrets resolved, so the Authorization header cannot be built and the request is rejected before sending.
Solutions
- Set the COMETAPI_KEY environment variable before making the call, e.g. export COMETAPI_KEY=<your-key>.
- Alternatively pass the credential directly via the api_key parameter in the litellm call.
- COMETAPI_API_KEY is also accepted.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/llms/cometapi/image_generation/transformation.py:97 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/f0d96c6fd609208c.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/cometapi/image_generation/transformation.py:97
)
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: str | None = api_key or get_secret_str("COMETAPI_KEY") or get_secret_str("COMETAPI_API_KEY")
if not final_api_key:
raise ValueError("COMETAPI_KEY or COMETAPI_API_KEY is not set")
headers["Authorization"] = f"Bearer {final_api_key}"
headers["Content-Type"] = "application/json"
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 CometAPI image generation request body
https://api.cometapi.com/v1/images/generations
"""View on GitHub (pinned to 77b7c6c40c)