Vercel AI SDK - Help
Answered
New Guinea Freshwater Crocodile posted this in #help-forum
New Guinea Freshwater CrocodileOP
I am sing the vercel AI sdk to build a react native app.
This is what I have in the FE to interact with the api endpoint;
I am using firebase and I want the api endpoint to only respond to authenticated requests. Is there a way built in way for me to send authentication data to the api endpoint where auth can be validated? Because by default, anyone can use the api endpoint.
Another thing; I want the AI to refer to the user by name so I need to be able to provide that data to the LLM.
This is what I have in the FE to interact with the api endpoint;
\javascript const { messages, error, handleInputChange, input, handleSubmit } = useChat({
initialMessages: [
{ id: "1", role: "assistant", content: "Let the cards guide your journey." },
],
fetch: expoFetch as unknown as typeof globalThis.fetch,
api: generateAPIUrl('/api/chat'),
onError: (err) => console.error(err, 'ERROR'),
});
I am using firebase and I want the api endpoint to only respond to authenticated requests. Is there a way built in way for me to send authentication data to the api endpoint where auth can be validated? Because by default, anyone can use the api endpoint.
Another thing; I want the AI to refer to the user by name so I need to be able to provide that data to the LLM.
48 Replies
New Guinea Freshwater CrocodileOP
Any help would be super appreciated
New Guinea Freshwater CrocodileOP
I cant find anything in the documentation, super stuck 🫠
"Firebase services (like Cloud Firestore, Authentication, Realtime Database, Remote Config, and more) are available to import within individual sub-packages."
New Guinea Freshwater CrocodileOP
I meant how can I send that data using the vercel SDK, the vercel ai SDK gives me access to the useChat hook (where I provide the api endpoint /api/chat), how can I send data through the hook? Otherwise I would have to leave my endpoint unauthenticated @gin
Really really appreciate the help
New Guinea Freshwater CrocodileOP
I do have an api endpoint already however the problem is passing the data to the API endpoint via the useChat hook provided by the vercel AI sdk
everything on the page
New Guinea Freshwater CrocodileOP
I have read everything a few times, there is no e.g of auth on there or passing custom data other than data required to run the LLM
wdym by custom data
u have to implement the auth yourself
New Guinea Freshwater CrocodileOP
I understand, the problem is;
useChat is a hook provided by vercel that helps you with LLM APIs
It lets you provide an API endpoint to your BE
yes? its on the page
New Guinea Freshwater CrocodileOP
But lets say if I want to pass in custom data (just as an e.g) the users first name to the BE, I cant find a way
using their hook
u usually handle authentication with a cookie
u can read it from the request object
New Guinea Freshwater CrocodileOP
Yeah but its a react native hook
react*
I cant pass cookies via hook
its available in the request object
New Guinea Freshwater CrocodileOP
I am trying to find the key that will let me pass the data using useChat
what is the key called, I am sorry but I cant see it
Maybe im being a really big idiot rn but I appreciate the help
I have read the documentation multiple times, and I dont see a way
"Requests use the global, standard Request object."
New Guinea Freshwater CrocodileOP
Maybe I am not communcating this right. The issue is passing the data to the api endpoint. I am aware on how to use the request object. useChat is a FE hook, I need to pass custom data into the useChat hook
I already have that part setup
if u want authentication u usually use your auth cookie and read it in your api route
idk what u want to pass in there cause the hook is to simplify the request
New Guinea Freshwater CrocodileOP
Legend!
Thank you so much
Really appreciate the help
u can mark this topic as answered
New Guinea Freshwater CrocodileOP
Of course!
thank you!