1010 python test_api.py
1111"""
1212
13+ import json
1314import os
15+
1416import requests
15- import json
1617
1718
1819def test_api_endpoint (api_key , endpoint_url , test_streaming = True ):
1920 """Test the 1min.ai API endpoint"""
2021
21- headers = {
22- "Authorization" : f"Bearer { api_key } " ,
23- "Content-Type" : "application/json"
24- }
22+ headers = {"Authorization" : f"Bearer { api_key } " , "Content-Type" : "application/json" }
2523
2624 # Test payload - adjust based on actual API requirements
2725 payload = {
28- "messages" : [
29- {"role" : "user" , "content" : "Hello! Please respond with 'API is working'." }
30- ],
26+ "messages" : [{"role" : "user" , "content" : "Hello! Please respond with 'API is working'." }],
3127 "temperature" : 0.7 ,
32- "max_tokens" : 50
28+ "max_tokens" : 50 ,
3329 }
3430
3531 print (f"Testing endpoint: { endpoint_url } " )
@@ -40,12 +36,7 @@ def test_api_endpoint(api_key, endpoint_url, test_streaming=True):
4036 print ("Testing NON-STREAMING response:" )
4137 print ("=" * 60 )
4238 try :
43- response = requests .post (
44- endpoint_url ,
45- headers = headers ,
46- json = payload ,
47- timeout = 30
48- )
39+ response = requests .post (endpoint_url , headers = headers , json = payload , timeout = 30 )
4940
5041 print (f"Status Code: { response .status_code } " )
5142 print (f"Response Headers:\n { json .dumps (dict (response .headers ), indent = 2 )} \n " )
@@ -69,19 +60,15 @@ def test_api_endpoint(api_key, endpoint_url, test_streaming=True):
6960
7061 try :
7162 with requests .post (
72- endpoint_url ,
73- headers = headers ,
74- json = payload ,
75- stream = True ,
76- timeout = 30
63+ endpoint_url , headers = headers , json = payload , stream = True , timeout = 30
7764 ) as r :
7865 print (f"Status Code: { r .status_code } \n " )
7966
8067 if r .status_code == 200 :
8168 print ("Streaming chunks:" )
8269 for line in r .iter_lines ():
8370 if line :
84- decoded = line .decode (' utf-8' )
71+ decoded = line .decode (" utf-8" )
8572 print (f" { decoded } " )
8673
8774 else :
0 commit comments