Licence
MIT
Version
0.5.1
Deps
0
Size
44 kB
Vulns
0
Weekly
0
@detent/sdk
Typed TypeScript client for the Detent rate-limiting API.
Status: pre-1.0 — the API may change between minor versions until 1.0.0.
Install
npm i @detent/sdk
Usage
import { Detent } from '@detent/sdk'
const rg = new Detent({ apiKey: process.env.DETENT_API_KEY! })
// Rate-limit check (always resolves; fails open by default on transport error)
const { allowed } = await rg.limit({ namespace: 'api', key: userId })
if (!allowed) return res.status(429).end()
// Concurrent-limit lease
await rg.withLease({ namespace: 'jobs', key: userId }, async () => {
await runExpensiveJob()
})
// Read-only usage stats
const stats = await rg.getStats({ namespace: 'api' })
Configuration
| Option | Default | Notes |
|---|---|---|
apiKey |
— (required) | rg_live_… / rg_test_… |
baseUrl |
https://api.detent.dev |
Override for self-host / tests |
timeoutMs |
1000 |
Client-side transport timeout |
failMode |
'open' |
'open' allows, 'closed' denies on transport error |
onError |
— | Called on transport errors and 5xx responses before fail-open/closed |
limit() never throws on a transport error or a 5xx server error — it returns { degraded: true } and respects failMode.
Only 4xx client errors (bad key, plan gate, unknown rule, malformed request) throw DetentApiError.