Skip to content

ToknWrks/regen-compute-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@toknwrks/regen-compute-client

TypeScript client for the Regenerative Compute API. Retire verified ecological credits from any JavaScript or TypeScript application.

Install

npm install @toknwrks/regen-compute-client

Usage

Get an API key at compute.regen.network.

import { RegenClient } from '@toknwrks/regen-compute-client'

const regen = new RegenClient({ apiKey: process.env.REGEN_API_KEY })

Retire credits

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
}

Estimate AI session footprint

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.00004

Browse available credits

const { marketplace_snapshot, sell_orders } = await regen.credits({ type: 'carbon' })

Get a retirement certificate

const cert = await regen.certificate('WyJy...')  // node ID or tx hash
console.log(cert.certificate_url)

Network impact stats

const impact = await regen.impact()
console.log(`${impact.active_projects} projects, ${impact.total_retirements} retirements`)

Error handling

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)
  }
}

Next.js

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',
  })
}

License

Apache-2.0

About

TypeScript client for the Regenerative Compute API — ecological credit retirement for AI applications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors