Do Convex actions have a timeout? If so, how long?
1. Does convex actions have limited timeout threshold similar to Vercel?
2. How would you implement something that requires long await time e.g. sending an API to a AI image generator that is experiencing cold start so it takes around 20 seconds?
- Would you break it into 2 steps i.e. send image generation request, then let the API call the webhook on the way back.
- Or would you just request the image generation process and await for 20 seconds inside convex action?
24 Replies
For context:
i am building a web app which allows users to upload their own photo and it'll generate 10 variations of the photo using AI. basically user will get 10 generated AI images.
user perspective: user upload the photo, he will see 10 spinning icons indicating that the image variations are being generated. as soon as any image finishes generation, it will replace spinning icon. not all 10 spinning icons will be done at the same time because it's 10 parallel requests to the AI.
I just want to know how to design the data flow process to work with Convex. I'm new to webdev in general (studied 3 weeks ago). Thanks.
hi! great questions! convex actions https://docs.convex.dev/functions/actions currently have a timeout of 5 minutes, so it should be possible to await a result within an action.
however, your webhook idea would be a little more efficient and more granular. for example, convex prices actions on GB*s, so an action that's waiting around for 20 seconds may cost more than a webhook-based approach (but it would still probably be fine, especially as a first implementation). check out this starter for streaming data from an action into convex https://stack.convex.dev/gpt-streaming-with-persistent-reactivity
Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment
GPT Streaming With Persistent Reactivity
Stream GPT responses without brittle browser-based HTTP streaming.
Multiplayer reactivity, persistence, reactivity via Convex. Using OpenAI’s beta v4....
Thanks @lee , 5 minutes is good enough for my prototype. I'll try to check the streaming project you suggested.
BTW, I've tried the
convex-tour-chat
tutorial and I mostly saw that the query and mutation functions are used in the browser client for reactivity purposes. Is it possible to use them in the server as well?for sure! what kind of server is it? on a Node.js server you can use
ConvexHttpClient
https://docs.convex.dev/api/classes/browser.ConvexHttpClient as described in the quickstart https://docs.convex.dev/quickstart/nodejs, (or if you want the reactivity you can use BaseConvexClient
but server-side reactivity is more difficult). On a python or rust server you can use our python or rust libraries, which have similar quickstarts.Class: ConvexHttpClient | Convex Developer Hub
browser.ConvexHttpClient
I'll use it on Node server on Vercel serverless functions. On browser I'll use Svelte so I'll check to see if it works. (I've only tried chat tutorial with react).
I just tried the NodeJS tutorial above and I got this error:
Could it be because I use
pnpm
instead of npm
to install the libraries?
OK I got it working now. I have to change the code to use ES6 style import:
But not sure why I need to do this when the tutorial doesn't do it.@Chanchana I see this too, thanks for reporting! The Node.js quickstart uses CommonJS syntax because that's more common in Node.js, but to use that require syntax without a bundler you need to generate CommonJS code with
npx convex codegen --commonjs
Do you have "type": "module" in your package.json to make this just work?Yes.
I'm having a hard time trying to make this work with Svelte?

(catching up on the thread) you want a reactive client? You can use BaseConvexClient in "convex/browser" or ConvexReactClient from "convex/react" even though you're in Node.js
Let me find an example of that
Yes, I want reactive client on the browser.
The NodeJS stuff was just me trying to learn the API
Oh sorry, Svelte in the browser right?
gotcha
Yes
I would use the the ConvexReactClient, that's simplest. This shows using it outside of a React app: https://observablehq.com/@ballingt/hello-convex
Observable
Hello Convex
How do you get shared, reactive server-side state for an Observable notebook? There are many ways: AWS, firebase, a slick solution from Tom Larkworthy — and now there's one more, Convex. You can sign up for the Convex at convex.dev. To use Convex in a webapp or from Node.js the standard
npm install convex
etc. is recommended, but in Observable...You can also use the BaseConvexClient to avoid the React dependency but there are more steps there
that looks quite perplexing. do you have a very simple project that shows how to link other frameworks other than React to a table in Convex?
I think that Convex should try to create that project for Svelte or other frameworks. I don't even need it to be beautiful. Just a page that renders a few documents from convex db. I can just go to modify the docs inside the convex dashboard and see if it's reactive.
or maybe this is discouraged? I'm not sure if i should use Convex.
We have folks using Convex with Vue and Solid, but there's not a good Svelte example. Rendering documents will be different in each framework, but this gist will be
Thanks I'll try it out. BTW, what do you mean by React dependency though? Would it interfere with my Svelte project?
Nope! You just need to have React installed.
this needs to be updated, but I did this awhile ago: https://github.com/jamwt/svelte-convex
GitHub
GitHub - jamwt/svelte-convex: Quick, rough example using Convex wit...
Quick, rough example using Convex with Svelte. Contribute to jamwt/svelte-convex development by creating an account on GitHub.
@jamwt I was trying to copy your code from https://github.com/jamwt/svelte-convex/blob/main/src/lib/convexSvelteClient.ts into my SvelteKit project but I got this error. Do you know why? Maybe it's because of the different convex version? I have 1.0.2
GitHub
svelte-convex/src/lib/convexSvelteClient.ts at main · jamwt/svelte-...
Quick, rough example using Convex with Svelte. Contribute to jamwt/svelte-convex development by creating an account on GitHub.

yep! it needs to be updated for 1.0. I can probably do a quick pass on it this afternoon and ping this thread
Thank you a lot. Can you do it in SvelteKit format? Because I think most people are familiar with it.
depends on how bit the lift is!
if it's a lot more work, might need to get to it later this week
ok if you can update
convexSvelteClient.ts
file in the repo above, It'd be enough for me to see how to incorporate into my SvelteKit project I guess