Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: move _set_usage_and_cost outside try/except in OpenRouter image edit

Chesars4b1389501d3f
diff --git a/litellm/llms/openrouter/image_edit/transformation.py b/litellm/llms/openrouter/image_edit/transformation.py
index 19931f00245..ed5e6ae67d5 100644
--- a/litellm/llms/openrouter/image_edit/transformation.py
+++ b/litellm/llms/openrouter/image_edit/transformation.py
@@ -242,9 +242,6 @@ class OpenRouterImageEditConfig(BaseImageEditConfig):
)
)
- self._set_usage_and_cost(model_response, response_json, model)
- return model_response
-
except Exception as e:
raise OpenRouterException(
message=f"Error transforming OpenRouter image edit response: {str(e)}",
@@ -252,6 +249,9 @@ class OpenRouterImageEditConfig(BaseImageEditConfig):
headers={},
)
+ self._set_usage_and_cost(model_response, response_json, model)
+ return model_response
+
def get_error_class(
self, error_message: str, status_code: int, headers: Union[dict, httpx.Headers]
) -> BaseLLMException: