{"record":{"id":"c28a6287de02030f","repo":"BerriAI/litellm","slug":"api-key-is-required-for-topaz-image-variations-se","errorCode":null,"errorMessage":"API key is required for Topaz image variations. Set via `TOPAZ_API_KEY` or `api_key=..`","messagePattern":"API key is required for Topaz image variations\\. Set via `TOPAZ_API_KEY` or `api_key=\\.\\.`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/topaz/common_utils.py","lineNumber":24,"sourceCode":"\n\nclass TopazException(BaseLLMException):\n    pass\n\n\nclass TopazModelInfo(BaseLLMModelInfo):\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        if api_key is None:\n            raise ValueError(\"API key is required for Topaz image variations. Set via `TOPAZ_API_KEY` or `api_key=..`\")\n        return {\n            # \"Content-Type\": \"multipart/form-data\",\n            \"Accept\": \"image/jpeg\",\n            \"X-API-Key\": api_key,\n        }\n\n    def get_models(self, api_key: str | None = None, api_base: str | None = None) -> list[str]:\n        return [\n            \"topaz/Standard V2\",\n            \"topaz/Low Resolution V2\",\n            \"topaz/CGI\",\n            \"topaz/High Resolution V2\",\n            \"topaz/Text Refine\",\n        ]\n\n    @staticmethod\n    def get_api_key(api_key: str | None = None) -> str | None:\n        return api_key or get_secret_str(\"TOPAZ_API_KEY\")","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/topaz/common_utils.py#L6-L42","documentation":"Topaz Labs image-variation support in LiteLLM requires an API key on every request: validate_environment raises immediately when the api_key argument is None, directing you to TOPAZ_API_KEY or the api_key parameter. Unlike some providers, this code path performs no environment lookup itself — the key must already be resolved (by LiteLLM's main handler from TOPAZ_API_KEY, or passed explicitly) when it reaches this check.","triggerScenarios":"Calling litellm.image_variation(model=\"topaz/Standard V2\", ...) without api_key while TOPAZ_API_KEY is not set in the environment; proxy deployments that omit litellm_params.api_key for the topaz model entry.","commonSituations":"New Topaz integration where the env var was never provisioned; containerized proxy missing the TOPAZ_API_KEY entry; assuming the key is optional because other image providers default differently; renaming the model provider prefix so key-resolution rules no longer match.","solutions":["Export TOPAZ_API_KEY in the process environment so LiteLLM resolves it for topaz/* models.","Pass api_key=\"...\" explicitly on the image_variation call.","For litellm proxy, set litellm_params.api_key on the topaz model_list deployment.","Verify with os.environ.get('TOPAZ_API_KEY') in the exact runtime before retrying."],"exampleFix":"# before\nresp = litellm.image_variation(model=\"topaz/Standard V2\", image=fp)\n# -> ValueError: API key is required for Topaz image variations...\n\n# after\nimport os\nresp = litellm.image_variation(\n    model=\"topaz/Standard V2\",\n    image=fp,\n    api_key=os.environ[\"TOPAZ_API_KEY\"],\n)","handlingStrategy":"validation","validationCode":"import os\n\n\ndef topaz_ready(api_key: str | None = None) -> bool:\n    return bool(api_key or os.environ.get(\"TOPAZ_API_KEY\"))\n\n\nif not topaz_ready():\n    raise RuntimeError(\"TOPAZ_API_KEY missing — topaz image variations unavailable\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_variation(model=\"topaz/Standard V2\", image=fp)\nexcept ValueError as e:\n    if \"API key is required for Topaz\" in str(e):\n        raise RuntimeError(\"configure TOPAZ_API_KEY or per-deployment api_key\") from e\n    raise","preventionTips":["Check provider credentials at startup for every model you expose.","In proxy deployments, always set litellm_params.api_key for topaz models.","Remember Topaz validation accepts only an explicit key here — don't rely on loose defaults."],"tags":["topaz","image-variation","api-key","environment-variables","litellm"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T11:17:13.642Z"}