Does anyone know how I can get the API's response status code successfully?
I already tried:
# Create the headers, providing the API key and version
auth = f'Bearer {openai.api_key}'
headers = {
'Authorization': auth,
'Content-Type': 'application/json',
'Accept': 'application/json',
}
check_status = requests.get("https://api.openai.com/v1/engines/davinci/completions", headers=headers)
status_code = check_status.status_code
# Check the response status
print("Response status of OpenAI:", status_code)
# Check the response text
print("Response text:", check_status.text)'
but I get 405 error :/
#Status code from response
26 messages · Page 1 of 1 (latest)
I would recommend not using requests and instead using the OpenAI module which does all the heavy lifting for you
I do use it to get the response but I didn't find any alternative to response.status_code as the requests package have
For whatever reason if you must use it, the correct url is https://api.openai.com/v1/completions
do you know how can I implement it with the open ai module?
OpenAI handles the response form you
*for you
Import openai
The examples in the API documentation include using the module for their examples
can I get the status code? from the open ai module?
I need the status code for unit testing
I honestly don't know how it handles any bad server codes
With this url I get error code 400
I'm sure it does,. I just don't know
You need to change it to requests.post first and the deliver a payload
If you strictly just want to try the server to see if it's available
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Model.list()
Easy with the module
curl https://api.openai.com/v1/models \
-H 'Authorization: Bearer YOUR_API_KEY'
With curl, but the same configuration can be used with Requests
Thanks, this is nice to check the availability of the server, but I need the status codes :/
What kind of unit tests do you hope to accomplish? The only codes I could imagine with a functional service would be 5x codes if the server is down