I tried Using the ChatGpt4 API and it didn't work

I tryed in my code using the GPT4 API.
I made an Account only for the API i have downloaded 25$ worth of credits and everytime i ask the model which model it is it says it is a GPT 3 Model

This is the code running in the terminal of VSCode

from flask import Flask, request, jsonify
import requests

app = Flask(name)

API_KEY = “sk-xx” # Replace with your actual API key

headers = {
“Authorization”: f"Bearer {API_KEY}"

def get_gpt4_response(prompt_text):
payload = {
“prompt”: prompt_text,
“max_tokens”: 150
response = requests.post(OPENAI_API_URL, headers=headers, json=payload)

if response.status_code == 200:
    return response.json()["choices"][0]["text"].strip()
    return "Error generating response"

def main():
print(“GPT-4 Chatbot (Type ‘exit’ to quit)”)
while True:
user_input = input("You: “)
if user_input.lower() == ‘exit’:
elif user_input.lower() == ‘which chatmodel of openai are you?’:
response = “I am GPT-4.”
response = get_gpt4_response(user_input)
print(f"GPT-4: {response}”)

if name == “main”:

If you’re calling the GPT-4 model, that’s what you’re using. Depending on your system and user/assistant messages, it might reply that it’s GPT-3.5 or even GPT-9! :wink:

1 Like