Error communicating with OpenAI: 404 The model `gpt-4o` does not exist or you do not have access to it

require("dotenv").config()
const OpenAI = require("openai")
const readlineSync = require("readline-sync")

// Open AI configuration
const openai = new OpenAI({
	apiKey: process.env.OPENAI_API_KEY
})

let messages = [{ role: "system", content: "You are a helpful assistant." }]

// Get user input
function getInput(promptMessage) {
	return readlineSync.question(promptMessage, {
		hideEchoBack: false // The typed characters won't be displayed if set to true
	})
}

async function main() {
	console.log("\n\n----------------------------------")
	console.log("          CHAT WITH AI 🤖   ")
	console.log("----------------------------------\n")
	console.log("type 'x' to exit the conversation")
	console.log(process.env.OPENAI_API_KEY)
	if (!process.env.OPENAI_API_KEY) {
		console.error("Error: OPENAI_API_KEY is not set in the environment variables.")
		process.exit(1) // Exit with error code 1
	}

	await runConversation()
}

async function runConversation() {
	while (true) {
		const input = getInput("You: ")
		if (input === "x") {
			console.log("Goodbye!")
			process.exit()
		}
		messages.push({ role: "user", content: input })
		try {
			const completion = await openai.chat.completions.create({
				model: "gpt-4o",
				messages: messages
			})
		} catch (error) {
			console.error("Error communicating with OpenAI:", error.message)
			continue // Skip this iteration
		}
	}
}

main()

getting this error—

Error communicating with OpenAI: 404 The model gpt-4o does not exist or you do not have access to it.

Is not free, for API you need credits to use it.
Those $18 are expired → poor marketing from OpenAI…

1 Like

I tried changing to gpt-3.5-turbo

It says now— Error communicating with OpenAI: 429 You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.

You need credits to use it, solved.

1 Like

I have deposited 5$now and still getting error — Error communicating with OpenAI: 429 You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.

They can help you with this problem: https://help.openai.com