customer()
Create, resolve, look up, list, and configure customers
customer()
Use fawran.customer() to create or resolve a customer by email or ID. The response includes the customer's current billing configuration, and the same namespace exposes helpers for customer-specific billing controls.
For the dedicated guide covering customer-level billing overrides, precedence, and recommended usage, see Customer Config.
For customer-facing usage charts and usage dashboards, the same namespace also exposes usageHistory().
Every read on this namespace (get(), usageHistory(), and the setters) accepts the same identifier you use in track() / check(): your own external customer ID, the customer's email, or the internal Fawran ID.
Signature
const customer = await fawran.customer({
id?: string, // Optional: Your customer ID
email: string, // Required: Customer email
name?: string, // Optional: Display name
metadata?: Record<string, unknown>, // Optional: Custom data
});
const customer = await fawran.customer.get(customer: string);
const page = await fawran.customer.list({
limit?: number, // 1-100, default 50
offset?: number, // default 0
search?: string, // substring match on email, name, externalId
email?: string, // exact (case-insensitive)
externalId?: string, // exact
});
await fawran.customer.setFeatureConfig({
customer: string,
feature: string,
overage?: "block" | "charge" | null,
maxOverageUnits?: number | null,
});
await fawran.customer.setOverageLimit({
customer: string,
maxOverageAmount: number | null,
onLimitReached?: "block" | "notify",
});
await fawran.customer.usageHistory({
customer: string,
range?: "7d" | "30d" | "90d" | "custom",
granularity?: "day" | "week" | "month",
feature?: string | null,
groupBy?: "total" | "feature",
timezone?: string,
from?: string,
to?: string,
});Parameters
fawran.customer(params)
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | - | Your internal customer ID |
email | string | ✅ | Customer email address |
name | string | - | Customer display name |
metadata | object | - | Custom key-value data |
fawran.customer.get(customer)
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | ✅ | External customer ID (what you pass to track), email, or internal ID |
Returns the same CustomerResult as fawran.customer(). Throws FawranError with Customer not found when nothing matches within your organization.
fawran.customer.list(params?)
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | number | - | Page size, 1–100. Defaults to 50. |
offset | number | - | Customers to skip. Defaults to 0. |
search | string | - | Case-insensitive substring match on email, name and external ID |
email | string | - | Exact email match (case-insensitive) |
externalId | string | - | Exact external ID match |
Results are newest first. total is the number of customers matching the filters, so offset + data.length < total means there is another page.
fawran.customer.setFeatureConfig(params)
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | ✅ | Customer ID or identifier |
feature | string | ✅ | Feature slug or ID |
overage | "block" | "charge" | null | - | Override overage behavior for this feature |
maxOverageUnits | number | null | - | Override the hard overage cap for this feature |
Provide at least one of overage or maxOverageUnits. Pass null to clear an existing override.
fawran.customer.setOverageLimit(params)
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | ✅ | Customer ID or identifier |
maxOverageAmount | number | null | ✅ | Customer-wide spend cap in minor units |
onLimitReached | "block" | "notify" | - | Behavior when the spend cap is reached. Defaults to block |
Pass null for maxOverageAmount to remove the spend cap.
fawran.customer.usageHistory(params)
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | ✅ | Customer ID |
range | "7d" | "30d" | "90d" | "custom" | - | Preset range or custom window. Defaults to 30d. |
granularity | "day" | "week" | "month" | - | Bucket size for aggregation. Defaults to day. |
feature | string | null | - | Optional feature slug or ID to filter to one feature. |
groupBy | "total" | "feature" | - | Return only the total series or include per-feature breakdowns. Defaults to total. |
timezone | string | - | IANA timezone used for bucket boundaries. Defaults to UTC. |
from | string | - | Inclusive YYYY-MM-DD start date when range is custom. |
to | string | - | Inclusive YYYY-MM-DD end date when range is custom. |
Use usageHistory() when you want chart-friendly usage buckets.
Use fawran.billing.usage() when you want uninvoiced overage and estimated billable amounts.
Returns
fawran.customer(), get(), setFeatureConfig(), and setOverageLimit() all return the customer plus the current customer billing config.
interface CustomerResult {
id: string; // Internal Fawran ID
externalId: string | null; // Your ID (the `customer` value you track with)
email: string;
name?: string | null;
metadata?: Record<string, unknown> | null;
billing: {
overageLimit: {
maxOverageAmount: number | null;
onLimitReached: "block" | "notify";
createdAt: number;
updatedAt: number;
} | null;
featureConfigs: Array<{
feature: {
id: string;
slug: string | null;
name: string;
};
overage: "block" | "charge" | null;
maxOverageUnits: number | null;
createdAt: number;
updatedAt: number;
}>;
};
createdAt: number;
updatedAt: number;
}fawran.customer.list() returns a page of lightweight customer summaries (no billing config):
interface CustomerListResult {
success: true;
data: Array<{
id: string;
externalId: string | null;
email: string;
name: string | null;
metadata: Record<string, unknown> | null;
createdAt: number;
updatedAt: number;
}>;
total: number;
limit: number;
offset: number;
}fawran.customer.usageHistory() returns aggregated usage history:
interface UsageHistoryResult {
customer: {
id: string;
};
query: {
range: {
from: string;
to: string;
};
granularity: "day" | "week" | "month";
feature: string | null;
groupBy: "total" | "feature";
timezone: string;
};
totals: {
usage: number;
records: number;
};
series: Array<{
bucket: string;
value: number;
}>;
breakdown: Array<{
feature: {
id: string;
slug: string | null;
name: string;
unit: string | null;
};
totals: {
usage: number;
records: number;
};
series: Array<{
bucket: string;
value: number;
}>;
}>;
}Examples
Create or Resolve a Customer
import { Fawran } from "@copto/fawran";
const fawran = new Fawran({ secretKey: process.env.FAWRAN_API_KEY });
// Create an org customer
const org = await fawran.customer({
email: "billing@acme.com",
name: "Acme Corporation",
metadata: { industry: "SaaS" },
});
console.log(org.id);
console.log(org.billing.overageLimit); // null by default
console.log(org.billing.featureConfigs); // []Resolve an Existing Customer
// Resolve existing customer by email
const existing = await fawran.customer({
email: "billing@acme.com",
});
// Or by your internal ID
const byId = await fawran.customer({
id: "org_acme",
email: "billing@acme.com",
});Look Up a Customer by Your Own ID
// The id you pass to track()/check() works for reads too
await fawran.track({ customer: "workspace_alpha", feature: "agent_turns" });
const customer = await fawran.customer.get("workspace_alpha");
console.log(customer.id); // internal UUID
console.log(customer.externalId); // "workspace_alpha"
// Email works as well
const byEmail = await fawran.customer.get("billing@acme.com");List and Search Customers
// First page, newest first
const page = await fawran.customer.list({ limit: 25 });
// Search across email, name and external id
const matches = await fawran.customer.list({ search: "acme" });
// Exact lookups
const { data } = await fawran.customer.list({ externalId: "workspace_alpha" });
// Walk every page
for (let offset = 0; ; offset += 100) {
const { data, total } = await fawran.customer.list({ limit: 100, offset });
for (const customer of data) console.log(customer.externalId ?? customer.email);
if (offset + data.length >= total) break;
}Set a Per-Feature Overage Policy
const updated = await fawran.customer.setFeatureConfig({
customer: "cust_123",
feature: "api_calls",
overage: "block",
maxOverageUnits: 1000,
});
console.log(updated.billing.featureConfigs);Set a Customer-Wide Overage Spend Cap
const updated = await fawran.customer.setOverageLimit({
customer: "cust_123",
maxOverageAmount: 500_000,
onLimitReached: "block",
});
console.log(updated.billing.overageLimit);Clear Customer Billing Overrides
await fawran.customer.setFeatureConfig({
customer: "cust_123",
feature: "api_calls",
overage: null,
maxOverageUnits: null,
});
await fawran.customer.setOverageLimit({
customer: "cust_123",
maxOverageAmount: null,
onLimitReached: "block",
});Get Aggregate Usage History
const history = await fawran.customer.usageHistory({
customer: "cust_123",
range: "30d",
granularity: "day",
groupBy: "total",
timezone: "Africa/Lagos",
});
console.log(history.totals.usage);
console.log(history.series);Get Per-Feature Usage History
const history = await fawran.customer.usageHistory({
customer: "cust_123",
range: "90d",
granularity: "week",
groupBy: "feature",
});
for (const feature of history.breakdown) {
console.log(feature.feature.slug, feature.totals.usage);
}Use a Custom Date Window
const history = await fawran.customer.usageHistory({
customer: "cust_123",
range: "custom",
granularity: "day",
from: "2026-04-01",
to: "2026-04-30",
});Using the Customer Object
The returned customer object has convenience methods:
const org = await fawran.customer({ email: "org@acme.com" });
// Attach subscription
await org.attach({ product: "team" });
// Manage entities (seats)
await org.addEntity({
feature: "seats",
entity: "user_123",
name: "John Doe",
});
const { entities } = await org.listEntities({ feature: "seats" });Entity Management Methods
Customer objects provide these entity management methods:
customer.addEntity(params)
Add an entity (e.g., seat) to the customer.
await org.addEntity({
feature: "seats",
entity: "user_123",
name: "John Doe",
email: "john@acme.com",
metadata: { role: "admin" },
});Parameters:
feature(string, required): Feature slugentity(string, required): Your entity IDname(string, optional): Display nameemail(string, optional): Contact emailmetadata(object, optional): Custom data
customer.removeEntity(params)
Remove an entity and free up the slot.
await org.removeEntity({
feature: "seats",
entity: "user_123",
});customer.listEntities(params?)
List entities for this customer.
// List all entities
const { entities } = await org.listEntities();
// Filter by feature
const { entities: seats } = await org.listEntities({ feature: "seats" });Best Practices
- Create early - Create the customer before attaching subscriptions or adding entities
- Use consistent IDs - Either always pass your own
idor always use email as identifier - Store metadata - Use metadata for customer segmentation and analytics
- Use spend caps as safety rails -
setOverageLimit()protects the whole customer across billable overage - Use feature config for exceptions -
setFeatureConfig()is best for one risky or contract-specific feature - Use usageHistory for charts -
usageHistory()is for usage dashboards, not invoice estimation - Update on changes - Call
customer()when user data changes to keep billing records in sync
Related
- Customer Config - Customer-level billing overrides and spend caps
- billing - Uninvoiced overage, invoices, and invoice generation
attach()- Subscribe customer to a plan- Overage - How plan overage and customer overrides interact
addEntity()- Add entities/seats (flat API)- Seat Pricing Guide - Complete seat-based billing walkthrough