Skip to main content

Installation

npm install @cred-protocol/sdk

Quick Start

import { CredClient } from '@cred-protocol/sdk'

const cred = new CredClient({ apiKey: process.env.CRED_API_KEY })

const result = await cred.evaluate({
  walletAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  policy: 'standard',
})

console.log(result.trustScore)  // 75
console.log(result.trustTier)   // "verified"
console.log(result.allPassed)   // true

Configuration

const cred = new CredClient({
  apiKey: 'cred_sk_...',       // Required
  baseUrl: 'https://...',      // Optional, defaults to production
})

Evaluate Options

Using a Policy Template

The simplest way to evaluate — pick a template that matches your use case:
const result = await cred.evaluate({
  walletAddress: '0x...',
  policy: 'standard',       // "basic", "standard", "strict", "financial", "reputation", "quick"
})

Using Custom Gates

For full control, specify individual gates:
const result = await cred.evaluate({
  walletAddress: '0x...',
  gates: ['human', 'verified', 'established'],
  operator: 'WEIGHTED',
  weights: { human: 0.4, verified: 0.35, established: 0.25 },
  compositeThreshold: 60,
})

With Dynamic Pricing

Compute trust-based pricing for your API:
const result = await cred.evaluate({
  walletAddress: '0x...',
  policy: 'reputation',
  includePricing: true,
  basePriceUsdc: 0.01,       // Your full price
})

console.log(result.priceMultiplier)    // 0.25 (verified tier)
console.log(result.suggestedPriceUsdc) // 0.0025

With Reputation Data

const result = await cred.evaluate({
  walletAddress: '0x...',
  policy: 'standard',
  includeReputation: true,    // Enabled by default
})

if (result.reputation) {
  console.log(result.reputation.settlementRate)    // 0.95
  console.log(result.reputation.totalEvaluations)  // 47
  console.log(result.reputation.riskFlags)          // []
}

Response Types

TrustResult

The evaluate() method returns a TrustResult:
FieldTypeDescription
walletAddressstringThe evaluated wallet
trustScorenumber0–100 composite score
trustTierTrustTiertrusted, verified, limited, untrusted, blocked
confidencenumber0.0–1.0 data confidence
allPassedbooleanWhether all gates passed
gateResultsGateScoreBreakdown[]Per-gate breakdown
priceMultipliernumber | nullDynamic pricing multiplier
suggestedPriceUsdcnumber | nullComputed price
reputationWalletReputation | nullBehavioral history
cachedbooleanWhether this was a cache hit
requestIdstringUnique request ID for debugging
challengeobject | null402 challenge body (if gates failed)
rawEvaluationResponseFull API response

GateScoreBreakdown

FieldTypeDescription
gateIdstringGate identifier (e.g., "human")
gateNamestringHuman-readable name
passedbooleanWhether this gate passed
scorenumber | null0–100 gate score
providerstring"cred" or third-party name

Error Handling

import { CredClient, CredAPIError } from '@cred-protocol/sdk'

try {
  const result = await cred.evaluate({ walletAddress: '0x...', policy: 'standard' })
} catch (err) {
  if (err instanceof CredAPIError) {
    console.log(err.status) // 401, 429, etc.
    console.log(err.body)   // Error details
  }
}
StatusMeaning
400Bad request — unknown policy or missing fields
401Invalid or missing API key
429Rate limit exceeded
502Upstream gate provider error

Framework Middleware

The core SDK is used by all framework middleware packages. If you’re using Hono, Express, Next.js, or FastAPI, see the dedicated middleware guides — they handle wallet extraction, 402 challenges, and trust headers automatically.

Hono

Drop-in Hono middleware

Express

Express middleware

Next.js

Next.js edge middleware

Python

Python + FastAPI