(SOLVED) Npm openai beta Trace: Error: 404 Invalid URL (POST /v1/assistants)

Im using the npm package however when running the sample from the docs, im getting:

Trace: Error: 404 Invalid URL (POST /v1/assistants)

Here is my example, am I missing something?

import { Context } from "hono";
import OpenAI from "openai";

export const createAssistant = async (c: Context) => {
	const openai = new OpenAI({
		apiKey: c.env.OPENAI_API_KEY,
	});

	const assistant = await openai.beta.assistants.create({
		name: "Math Tutor",
		instructions: "You are a personal math tutor. Write and run code to answer math questions.",
		tools: [{ type: "code_interpreter" }],
		model: "gpt-4-1106-preview"
	});

	const { id, name, instructions, tools, model } = assistant;

	const retrieveAssistant = await openai.beta.assistants.retrieve(id)

	console.log('retrieveAssistant', retrieveAssistant);

	const thread = await openai.beta.threads.create({ messages: [] });

	const message = await openai.beta.threads.messages.create(
		thread.id,
		{
			role: "user",
			content: "I need to solve the equation `3x + 11 = 14`. Can you help me?"
		}
	);

	console.log('message', message);

	const runCreate = await openai.beta.threads.runs.create(
		thread.id,
		{
			assistant_id: assistant.id,
			instructions: "Please address the user as Jane Doe. The user has a premium account."
		}
	);

	const runRetrieve = await openai.beta.threads.runs.retrieve(
		thread.id,
		runCreate.id
	);

	return c.json(runRetrieve)
}

murphy’s law, after I post, it starts working

I have a similar issue with ASSISTANTS API, but did not solved just like that.

Im getting 404 error while trying to connect to hps://api.openai.com/v1/assistants/asst_m************DG/messages.

error at Chrome Console:
POST h**ps://api.openai.com/v1/assistants/asst_m**************DG/messages 404 (Not Found)

Code of my app:

        const response = await fetch("hps://api.openai.com/v1/assistants/asst_m**************DG/messages", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                Authorization: "Bearer sk-W*********************f",
            },
            body: JSON.stringify({
                name: "test2",
                insturctions: "you are super happy about anything",
                model: "gpt-4-1106-preview",
                messages: [
                    { role: "system", content: "You are a helpful assistant." },
                    { role: "user", content: question },
                ],
            }),
        });

error at POSTMAN:

{
    "error": {
        "message": "Invalid URL (POST /v1/assistants/asst_m**************DG/messages)",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}

And the same with TEXT-TO-SPEECH API:


app.use(cors());
app.use(express.json()); // Adding middleware to process JSON

app.post('/text-to-speech', (req, res) => {
    const url = 'https://api.openai.com/v1/text-to-speech';
    console.log("Request received:", req.body);

    fetch(url, {
        method: 'POST',
        headers: {
            'Authorization': `Bearer sk-W*********************f`,
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(req.body)
    })
    .then(response => response.json())
    .then(data => {
        console.log("Response from OpenAI:", data);  // Adding logging here
        res.json(data);
    })
    .catch(error => {
        console.error("Error:", error);
        res.status(500).json({ error });
    });
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

Response is:

 error: {
    message: 'Invalid URL (POST /v1/text-to-speech)',
    type: 'invalid_request_error',
    param: null,
    code: null
  }

Does anybody else have a similar issue, or do I need to activate the use of those APIs somewhere in my account?

1 Like