anasfsd123 commited on
Commit
7868f23
·
verified ·
1 Parent(s): 91f134e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -16
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
- response = requests.post(
850
- "https://api.aimlapi.com/v1/responses",
851
- headers={
852
- "Content-Type":"application/json",
853
-
854
- # Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
855
- "Authorization":"Bearer <YOUR_AIMLAPI_KEY>",
856
- "Content-Type":"application/json"
857
- },
858
- json={
859
- "model":"openai/gpt-5-2025-08-07",
860
- "input":"Hello" # Insert your question for the model here, instead of Hello
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