Developers
Connecting to Privy
Set up a small, reliable API client.
A small wrapper that adds the key, sets a timeout and turns error envelopes into exceptions covers most integrations.
const BASE = "https://privy.ac/api/v1"
export async function privy(path, { signal } = {}) {
const res = await fetch(BASE + path, {
headers: { "X-API-Key": process.env.PRIVY_API_KEY },
signal: signal ?? AbortSignal.timeout(10_000),
})
const body = await res.json()
if (!res.ok) {
const err = new Error(body.error.message)
err.code = body.error.code
err.status = res.status
err.requestId = body.requestId
err.retryAfter = Number(res.headers.get("Retry-After")) || null
throw err
}
return body
}