Skip to content

A programming framework for agentic AI

raise error for content_filter (#849)

Chi Wang31c166435e7e
diff --git a/autogen/oai/client.py b/autogen/oai/client.py
index 70a28e15e..147f412fd 100644
--- a/autogen/oai/client.py
+++ b/autogen/oai/client.py
@@ -248,12 +248,16 @@ class OpenAIWrapper:
continue # filter is not passed; try the next config
try:
response = self._completions_create(client, params)
- except APIError:
+ except APIError as err:
+ error_code = getattr(err, "code", None)
+ if error_code == "content_filter":
+ # raise the error for content_filter
+ raise
logger.debug(f"config {i} failed", exc_info=1)
if i == last:
raise
else:
- # add cost calculation before caching not matter filter is passed or not
+ # add cost calculation before caching no matter filter is passed or not
response.cost = self.cost(response)
self._update_usage_summary(response, use_cache=False)
if cache_seed is not None: