Im able to connect to the regular GPT using the API from localhost, npm start. using React-19 and Expo. When I try to use the assistant ID I can’t figure out if the endpoint is incorrect or if there is a CORS issue with Assistants. I’m thinking if regular GPT API calls work that CORS shouldn’t be the issue. Here’s the code. Local host is http vs https, but again regular calls to API work. Tried CURL PHP and now NODE js. Funny thing is I was pulling from thread ID on the PHP attempt. These are two projects but the Node.JS. React-19 is the code here.
// src/ChatForm.js
import React, { useState } from ‘react’;
import axios from ‘axios’;
const ChatForm = () => {
const [inputText, setInputText] = useState(‘’);
const [response, setResponse] = useState(‘’);
const [loading, setLoading] = useState(false);
const handleSubmit = async (event) => {
event.preventDefault();
setLoading(true);
try {
const apiKey = ‘KEY-HERE’; // Replace with your actual OpenAI API key
const assistantId = ‘ID-here’; // Replace with your Assistant ID from the Playground
const result = await axios.post(
https://api.openai.com/v1/assistants/${assistantId}/completions,
{
messages: [
{ role: ‘user’, content: inputText },
],
max_tokens: 150,
},
{
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’: Bearer ${apiKey},
},
}
);
setResponse(result.data.choices[0].message.content);
} catch (error) {
console.error(‘Error fetching the OpenAI API:’, error.response ? error.response.data : error.message);
setResponse(‘An error occurred. Please try again.’);
} finally {
setLoading(false);
}
};
return (
<input
type=“text”
value={inputText}
onChange={(e) => setInputText(e.target.value)}
placeholder=“Ask the assistant something…”
/>
Send
{loading &&
{response &&
{response}
);
};
export default ChatForm;