Connect ChatGPT 3.5 free version through Python Script

Hello Team,

I want to connect ChatGPT 3.5 free version through Python Script.
I did use “hhttpss” instead of “http” due to link is not allowed to post here.
Here is my created code for it:

import os
import requests

Replace with the path to your secure configuration file

CONFIG_FILE_PATH = r"path…\config.txt"
def get_api_key():
“”“Reads the API key securely from the configuration file.”“”
with open(CONFIG_FILE_PATH, “r”) as file:
return file.readline().strip() # Read first line and remove leading/trailing whitespace
except FileNotFoundError:
raise SystemExit(f"Error: Configuration file not found: {CONFIG_FILE_PATH}")

def connect_and_send_query(query, model, api_key):
“”“Connects to ChatGPT, sends the query, and returns the response.”“”
# ChatGPT API endpoint (replace if necessary)
url = “hhttpss://”

    # Headers and content (adjust based on ChatGPT API requirements)
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    data = {
        "model": model,
        "prompt": query,
        "max_tokens": 1024,
        "n": 1,
        "stop": None,
        "temperature": 0.7,

    # Send request and handle response
    response =, headers=headers, json=data)
    response.raise_for_status()  # Raise an error for non-2xx status codes

    # Extract response from JSON and return
    return response.json()["choices"][0]["text"]
except Exception as e:
    print(f"Error sending query: {e}")
    return None

Example query and model

query = “What is the capital of France?”
model = “gpt-3.5-turbo-instruct”

Read API key securely

api_key = get_api_key()

Send query and print response

response = connect_and_send_query(query, model, api_key)

if response:
print(f"ChatGPT Response for ‘{query}’:")

Error is:
Error sending query: 429 Client Error: Too Many Requests for url: h

Process finished with exit code 0

Can anyone suggest on what went wrong in my script. Thank You.