Using Actions, Mutations, and Helpers in Convex for OpenAI Integration
I'm working on an app with Convex and have a quick question about structuring API calls and data handling. I'm integrating OpenAI to generate content and need some advice on the right approach using Convex's capabilities.
My current plan is to:
Use an action to call the OpenAI API.
Save the API response using a mutation.
Trigger the next step with a helper function.
I'm wondering if this is a sound approach, particularly regarding the use of actions to handle external API calls and then using mutations for database updates. Does anyone have experience with a similar setup or suggestions on whether this is the optimal way to handle such workflows in Convex? I made a diagram to illustrate what I mean
Any insights or tips would be greatly appreciated!
2 Replies
in general, this is how you integrate external data (like LLM activity) into convex apps, yep. action for the async call, mutation to record the result of the call within the database
I'm a little less clear on the helper -- this is something subscribed to a query that observes the data change when the mutation commits?
if so, yes, this is how its done
Thanks Jamie
Yes, that's essentially what I have in mind re the helper function, along with some conditional logic and spam filtration