Error: 404 Client Error: Not Found for url

When I am passing the text input in this function that I have created when we are requesting the URL it throws a 404 error even though the URL is right.

def get_investment_suggestion(input_text):
    # Define the API endpoint
    api_endpoint = "https://api.openai.com/v1/completions"

    # Define the request headers with your API key
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }

    # Define the data to be sent to the API
    data = {
        "model": "text-davinci-003",
        "prompt": input_text,
        "max_tokens": 100,  # Adjust max_tokens as needed
        "temperature": 0.7  # Adjust temperature for diversity of responses
    }

    # Send a POST request to the API
    try:
        response = requests.post(api_endpoint, headers=headers, json=data)
        response.raise_for_status()  # Raise an exception for HTTP errors
        if response.status_code == 200:
            return json.loads(response.text)["choices"][0]["text"].strip()
        else:
            return f"Error: Unexpected status code {response.status_code}"
    except requests.exceptions.RequestException as e:
        return f"Error: {e}"

Error: 404 Client Error: Not Found for url:

Welcome to the Community!

On of the issues in your code is that the model text-davinci-003 was deprecated in January this year. If you are looking to use an instruct model, then you now need to use gpt-3.5-turbo-instruct instead. The endpoint remains the same.

1 Like