diff --git a/vapi_python/vapi_python.py b/vapi_python/vapi_python.py index 69e9797..9b4aa11 100644 --- a/vapi_python/vapi_python.py +++ b/vapi_python/vapi_python.py @@ -13,13 +13,16 @@ def create_web_call(api_url, api_key, payload): 'Content-Type': 'application/json' } response = requests.post(url, headers=headers, json=payload) + response.raise_for_status() + + # Check for 201 Created explicitly, although raise_for_status handles 4xx/5xx + if response.status_code != 201: + raise Exception(f"Unexpected status code: {response.status_code}") + data = response.json() - if response.status_code == 201: - call_id = data.get('id') - web_call_url = data.get('webCallUrl') - return call_id, web_call_url - else: - raise Exception(f"Error: {data['message']}") + call_id = data.get('id') + web_call_url = data.get('webCallUrl') + return call_id, web_call_url class Vapi: