TypeScript client for the Regenerative Compute API. Retire verified ecological credits from any JavaScript or TypeScript application.
npm install @toknwrks/regen-compute-clientGet an API key at compute.regen.network.
import { RegenClient } from '@toknwrks/regen-compute-client'
const regen = new RegenClient({ apiKey: process.env.REGEN_API_KEY })const result = await regen.retire({
credit_class: 'C', // carbon
quantity: 1,
beneficiary_name: 'Acme AI',
jurisdiction: 'US',
reason: 'AI session footprint',
})
if (result.status === 'success') {
console.log(result.certificate_url) // shareable on-chain proof
} else {
console.log(result.marketplace_url) // fallback credit card link
}const footprint = await regen.footprint({
session_minutes: 30,
tool_calls: 12,
})
console.log(footprint.co2_kg) // e.g. 0.042
console.log(footprint.equivalent_carbon_credits) // e.g. 0.00004const { marketplace_snapshot, sell_orders } = await regen.credits({ type: 'carbon' })const cert = await regen.certificate('WyJy...') // node ID or tx hash
console.log(cert.certificate_url)const impact = await regen.impact()
console.log(`${impact.active_projects} projects, ${impact.total_retirements} retirements`)import {
RegenAuthError,
RegenRateLimitError,
RegenNotFoundError,
RegenApiError,
} from '@toknwrks/regen-compute-client'
try {
await regen.retire({ quantity: 1 })
} catch (err) {
if (err instanceof RegenRateLimitError) {
console.log(`Retry in ${err.retryAfter}s`)
} else if (err instanceof RegenAuthError) {
console.log('Check your API key')
} else if (err instanceof RegenApiError) {
console.log(err.status, err.code, err.message)
}
}Store your key in .env.local and use the client in server components or server actions — the key never reaches the browser:
// app/actions/retire.ts
'use server'
import { RegenClient } from '@toknwrks/regen-compute-client'
const regen = new RegenClient({ apiKey: process.env.REGEN_API_KEY! })
export async function retireForSession(minutes: number) {
const footprint = await regen.footprint({ session_minutes: minutes })
return regen.retire({
credit_class: 'C',
quantity: footprint.equivalent_carbon_credits,
reason: 'AI session footprint',
})
}Apache-2.0