@@ -130,3 +130,33 @@ def __ne__(self, other):
130130 return True
131131
132132 return self .to_dict () != other .to_dict ()
133+
134+
135+ def get_response_metadata (response ):
136+ """Extract ResponseMetadata from a Volcengine API response object.
137+
138+ :param response: A response object returned by a service API call,
139+ or a raw dict containing a 'ResponseMetadata' key.
140+ :return: ResponseMetadata instance if available, otherwise None.
141+ :rtype: ResponseMetadata or None
142+ """
143+ # Case 1: Typed response model with _metadata (from generated service APIs)
144+ if hasattr (response , '_metadata' ):
145+ meta = response ._metadata
146+ if isinstance (meta , ResponseMetadata ):
147+ return meta
148+ return None
149+
150+ # Case 2: Raw dict with "ResponseMetadata" key
151+ if isinstance (response , dict ):
152+ meta_dict = response .get ('ResponseMetadata' )
153+ if isinstance (meta_dict , dict ):
154+ return ResponseMetadata (
155+ service = meta_dict .get ('Service' ),
156+ action = meta_dict .get ('Action' ),
157+ version = meta_dict .get ('Version' ),
158+ region = meta_dict .get ('Region' ),
159+ request_id = meta_dict .get ('RequestId' )
160+ )
161+
162+ return None
0 commit comments