Using Open AI API
I would like to call with action open API to get some data, but then I need to return somehow this data to my frontend. How can I do that? After action is executed I need to run some query? in your chat example you are executing a mutation. I don't want to store the response in DB.
7 Replies
Storing the response in the DB is the simplest way to do this — you can always delete it later.
But if it's important not to store the result (I'd love to hear more about this) you can return the response from the action. Call the action directly from the client, and in the action get the openai response.
How can access response from action on client?
I'm using something like this, but how can I access here a response?
generateDomains
is an async function which returns a promise of whatever the Convex function returns
So something like
ok got it, thank you
you'll also need to write your action such that it returns a valid Convex object (like
{ response: "this is the text response" }
)but it's safe to do like that? let's say I want to run something with OpenAPI key, when I'm exposing that action to client view, someone can get my key?
The action runs on the server, clients can't see this code. Indeed you shouldn't return a secret key from an action, you should just return the data the client needs.