Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -845,21 +845,27 @@ if __name__ == "__main__":
|
|
| 845 |
|
| 846 |
import requests
|
| 847 |
import json # for getting a structured output with indentation
|
|
|
|
| 848 |
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
|
| 864 |
-
data = response.json()
|
| 865 |
-
print(json.dumps(data, indent=2, ensure_ascii=False))
|
|
|
|
| 845 |
|
| 846 |
import requests
|
| 847 |
import json # for getting a structured output with indentation
|
| 848 |
+
import os
|
| 849 |
|
| 850 |
+
api_key = os.getenv("AI_ML_API_KEY") # or st.secrets["AI_ML_API_KEY"]
|
| 851 |
+
if not api_key:
|
| 852 |
+
raise ValueError("AI_ML_API_KEY not set in environment variables.")
|
| 853 |
+
print(f"API key loaded, length: {len(api_key)}") # check without printing the key itself
|
| 854 |
+
url = "https://api.aimlapi.com/v1/responses"
|
| 855 |
+
headers = {
|
| 856 |
+
"Content-Type": "application/json",
|
| 857 |
+
"Authorization": f"Bearer {api_key}"
|
| 858 |
+
}
|
| 859 |
+
payload = {
|
| 860 |
+
"model": "openai/gpt-5-2025-08-07",
|
| 861 |
+
"input": "Hello"
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 865 |
+
|
| 866 |
+
if response.status_code != 200:
|
| 867 |
+
print(f"Error {response.status_code}: {response.text}")
|
| 868 |
+
else:
|
| 869 |
+
data = response.json()
|
| 870 |
+
print(json.dumps(data, indent=2, ensure_ascii=False))
|
| 871 |
|
|
|
|
|
|