Check rate limit without decrementing remaining
frasermarch opened this issue · comments
Preliminary Checks
-
I have reviewed https://unkey.com/docs for existing features that would solve my problem
-
I have searched for existing feature requests: https://github.com/unkeyed/unkey/issues
-
This issue is not a question, general help request, or anything other than a feature request directly related to Unkey. Please ask questions in our Discord community: https://unkey.com/discord.
Is your feature request related to a problem? Please describe.
I have an expensive query that I would like to rate limit, but in the case that the query fails I don't want the users remaining limit to be effected.
Describe the solution
const { remaining } = await unkey.limit("my-user-id", {decrement=false})
or
const { remaining } = await unkey.checkLimit("my-user-id")
Describe alternatives you have considered (if any)
No response
Additional context
No response
Agreed, this is useful
it could work by setting {cost: 0}
but we have a check in the api right now that only accepts >= 1 values, should be an easy fix though
@frasermarch here you go
it's not the nicest API and a seperate function would be nice, but it works
const { remaining } = await unkey.limit("my-user-id", { cost: 0 })
That's great - thank you!