code: def is_api_error(err: Exception) -> bool:
      if isinstance(err, httpx.HTTPStatusError):
          response = err.response
          error_data = response.json().get("error", {})
          error_message = error_data.get("message")
          if response.status_code in [400, 404, 415]:
              if error_data.get("type") == "idempotency_error":
                  print(
                      f"Retrying after idempotency error: {error_message} ({response.url})"
                  )
                  return True
              else:
                  # Invalid request
                  return False
          else:
              print(
                  f"Retrying after API error: {error_message} ({response.url})"
              )
              return True
  
      elif isinstance(err, httpx.ConnectError):
          print(
              f"Retrying after connection error... ({err.request.url})"
          )
          return True
  
      elif isinstance(err, httpx.TimeoutException):
          print(
              f"Retrying after a timeout error... ({err.request.url})"
          )
          return True
  
      elif isinstance(err, httpx.ReadError):
          print(f"Retrying after a read error... ({err.request.url})")
          return True
  
      print(f"Retrying after an unexpected error: {repr(err)}")
      traceback.print_tb(err.__traceback__)
      return True
  
file_path: automated-interpretability/neuron-explainer/neuron_explainer/api_client.py
imports: import asyncio
  import contextlib
  import os
  import random
  import traceback
  from asyncio import Semaphore
  from functools import wraps
  from typing import Any, Callable, Optional
  import httpx
  import orjson
label_desc: Use image node_id 1 for calling a global function with example usage: is_api_error(err) and returns: True, True, True, True, False, True, True