I’m getting 404 when trying to use chatGPT turbo… why?
that’s a python script I’m trying to run:
import requests
api_key = “sk-proj-myapikeyhere”
headers = {
“Authorization”: f"Bearer {api_key}"
}
def generate_random_sentence():
prompt = “Generate a random sentence.”
data = {
“model”: “gpt-4-turbo”,
“prompt”: prompt,
“temperature”: 0.7,
“max_tokens”: 60
}
#removed url becaue I connat include links on the post
response = requests.post(“api_openai_com-v1-chat-completions”, headers=headers, json=data)
if response.status_code == 200:
response_json = response.json()
if 'choices' in response_json and response_json['choices']:
return response_json['choices'][0].get('text', '').strip()
else:
return "Error: 'choices' key not found or empty in response."
else:
return f"Error: API request failed with status code {response.status_code}."
print(generate_random_sentence())