CacheReplayClosureError on cached API calling function

Running Streamlit locally, version 1.49.1.

I have an app, and it calls a bit of info from an API on a server. The API client is implemented in an external class in an included module.

I want to use @st.cache_data on the function to limit calls that have already been made before. Code for the function looks like this:

@st.cache_data(ttl=3600)
def get_item_name(item_id: str, url: str) -> str:
    """
    Retrieve item name from API with caching based on item ID.    
    """
    try:
        client = ExternalAPIClient(<args to init the client>)
        item = client.get_item(item_id)
        item_name = item['fields'].get('name', 'Item not found')
    except Exception as e:
        item_name = f"Could not retrieve item: {e}"
    
    return item_name

When I run this, whenever the function is called a second time, I get this error:

CacheReplayClosureError: While running get_item_name(), a streamlit element is
called on some layout block created outside the function. This is incompatible with replaying the cached effect of that element, because the referenced block might not exist when
the replay happens.

There’s no Streamlit block whatsoever that is modified from within the function. The API Client has no interaction with the Streamlit GUI, it is merely included once.

I searched for this error message, could not find any other post mentioning it. Any ideas what may cause this?