URL: https://wattfare.com/docs
# Wattfare documentation

> Wattfare is an OAuth-like consent layer for AI spend. Your users connect their own inference budget, set a cap, and you call any model through one SDK — charged to them, not you.

Shipping an AI feature usually means **you** pay for every token your users burn. Costs are unpredictable, a single power user can wreck your margins, and you carry the risk. Wattfare flips that around: your users bring their own AI budget and approve a spending cap once, in a hosted consent popup. You make model calls on their behalf — metered against that budget, billed to them.

Think **“Sign in with Google”, but for AI spend**. One button connects a user's inference budget to your app: metered, capped, and revocable at any time. Your secret key never leaves your backend; the browser only ever holds a short-lived, scoped session token.

## Why Wattfare

- **Predictable costs** — Your users' spend is their own. No surprise inference bills, no per-seat AI pricing you have to model and absorb.
- **One SDK, every model** — An OpenAI-compatible proxy backs hundreds of models. Swap openai/gpt-4o-mini for anthropic/claude-sonnet-4 with a string.
- **Users stay in control** — Caps are enforced upstream. Users can see usage and revoke any app from their dashboard — which is exactly what builds trust.
- **No secrets in the browser** — The frontend forwards a 10-minute JWT minted by your backend. The secret key and the user's funding source never touch the client.

## Three SDK surfaces

The `wattfare` package has no root export — you import only the surface you need. Each is a thin, focused layer over the same HTTP API.

- [Server SDK](https://wattfare.com/docs/server-sdk) — Holds your secret key. Mints session tokens and runs inference on a user's behalf.
- [Client SDK](https://wattfare.com/docs/client-sdk) — Runs in the browser. Opens the consent popup and reads connection status.
- [React SDK](https://wattfare.com/docs/react-sdk) — A provider and a useWattfare() hook that wire the whole flow into React.

## At a glance

Installing is one command. On your backend, inference is a drop-in AI SDK provider — if you've used the Vercel AI SDK, this will look familiar:

```bash
npm install wattfare
```

```ts
import { Wattfare } from "wattfare/server";
import { generateText } from "ai";

const wf = new Wattfare({ secretKey: process.env.WATTFARE_SECRET_KEY! });

// Scoped to one of *your* user ids — no Wattfare account for end users.
const ai = wf.user("user_123");

const { text } = await generateText({
  model: ai.model("openai/gpt-4o-mini"), // billed to the user's budget
  prompt: "Say hello.",
});
```

The only Wattfare-specific lines are constructing the client and calling `wf.user(id)`. Everything downstream is standard AI SDK. Usage is metered automatically against the connected user's budget.

> **Developer preview**
>
> Wattfare is in developer preview. The SDK surface documented here is stable; spending limits are soft-enforced for now. Have feedback or hit a rough edge? [hello@wattfare.com](mailto:hello@wattfare.com).

## Start here

- [Quickstart](https://wattfare.com/docs/quickstart) — Wire up a working “Connect AI budget” button end-to-end in about five minutes.
- [How it works](https://wattfare.com/docs/concepts) — The consent flow, keys, sessions, and metering — the model behind the SDK.
- [Next.js guide](https://wattfare.com/docs/guides/nextjs) — A complete App Router integration with streaming chat, copy-paste ready.
- [HTTP API](https://wattfare.com/docs/api-reference) — The raw REST endpoints, for debugging or building on a stack the SDK doesn't cover.
