unkeyed / unkey

Open source API management platform

Home Page:https://go.unkey.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check rate limit without decrementing remaining

frasermarch opened this issue · comments

Preliminary Checks

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!