{"record":{"id":"d6423cffe29b3ae2","repo":"BerriAI/litellm","slug":"api-key-is-required-for-topaz-image-variations","errorCode":null,"errorMessage":"API key is required for Topaz image variations","messagePattern":"API key is required for Topaz image variations","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/images/main.py","lineNumber":678,"sourceCode":"            raise ValueError(\"API key is required for OpenAI image variations\")\n        if api_base is None:\n            raise ValueError(\"API base is required for OpenAI image variations\")\n\n        response = openai_image_variations.image_variations(\n            model_response=model_response,\n            api_key=api_key,\n            api_base=api_base,\n            model=model,\n            image=image,\n            timeout=litellm_params.get(\"timeout\", None),\n            custom_llm_provider=custom_llm_provider,\n            logging_obj=litellm_logging_obj,\n            optional_params={},\n            litellm_params=litellm_params,\n        )\n    elif image_variation_provider == LITELLM_IMAGE_VARIATION_PROVIDERS.TOPAZ:\n        if api_key is None:\n            raise ValueError(\"API key is required for Topaz image variations\")\n        if api_base is None:\n            raise ValueError(\"API base is required for Topaz image variations\")\n\n        response = base_llm_aiohttp_handler.image_variations(\n            model_response=model_response,\n            api_key=api_key,\n            api_base=api_base,\n            model=model,\n            image=image,\n            timeout=litellm_params.get(\"timeout\", None) or DEFAULT_REQUEST_TIMEOUT,\n            custom_llm_provider=custom_llm_provider,\n            logging_obj=litellm_logging_obj,\n            optional_params={},\n            litellm_params=litellm_params,\n            client=client,\n        )\n\n    # return the response","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/images/main.py#L660-L696","documentation":"The Topaz branch of litellm.image_variation resolves the key via provider_config.get_api_key (litellm_params api_key falling back to TOPAZ_API_KEY env) and requires it non-None before dispatching to base_llm_aiohttp_handler.image_variations. Topaz has no anonymous access, so an unresolved key aborts the call.","triggerScenarios":"litellm.image_variation(model='topaz/...', image=...) without api_key while TOPAZ_API_KEY is unset; running the proxy in an environment where the Topaz secret was never added; typos in the env var name (e.g. TOPAZ_KEY) so the fallback misses.","commonSituations":"Docker/systemd units missing the secret; rotating a leaked key and forgetting to update the deployment; local shell has the var but the spawned worker does not.","solutions":["Export TOPAZ_API_KEY in the process that runs litellm.","Or pass api_key explicitly in the image_variation call / Router litellm_params.","Store it in the proxy's environment_config_settings / secret manager so workers inherit it.","Add a startup assertion for required env vars per provider you enable."],"exampleFix":"# before\nresp = litellm.image_variation(model=\"topaz/upscayl\", image=img, api_base=\"https://www.topazlabs.com/api\")\n# ValueError: API key is required for Topaz image variations\n\n# after\nexport TOPAZ_API_KEY=...\nresp = litellm.image_variation(model=\"topaz/upscayl\", image=img, api_base=\"https://www.topazlabs.com/api\")","handlingStrategy":"validation","validationCode":"import os\n\napi_key = os.getenv(\"TOPAZ_API_KEY\")\nif not api_key:\n    raise RuntimeError(\"TOPAZ_API_KEY not set; required for Topaz image variations\")\nresp = litellm.image_variation(model=\"topaz/upscayl\", image=img, api_key=api_key, api_base=\"https://www.topazlabs.com/api\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_variation(model=\"topaz/upscayl\", image=img, api_base=base)\nexcept ValueError as e:\n    if \"API key is required for Topaz image variations\" in str(e):\n        raise RuntimeError(\"set TOPAZ_API_KEY or pass api_key=\") from e\n    raise","preventionTips":["Add TOPAZ_API_KEY to the deployment env spec (compose/k8s secret) when enabling topaz models.","Boot-time assert required env vars per enabled provider.","Name the env var exactly TOPAZ_API_KEY — the provider config fallback is name-sensitive."],"tags":["litellm","image-variation","topaz","api-key","credentials"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}