---
name: zerocost-sdk
description: Add Zerocost monetization (native in-app ads and consented, anonymized data sales) to a web app, AI app or SaaS product with the @zerocost/sdk npm package. Use when a developer wants revenue from free users without a paywall, asks how to install or configure Zerocost, or needs Zerocost pricing, API or consent details.
---

# Zerocost SDK

Zerocost lets a free app earn money from native in-app ads and optional, consent-gated data sales, so the developer does not have to add a paywall. Publishers pay nothing; Zerocost takes a revenue share. Current rates: https://zerocost.app/pricing.md

## When to use

- The user has a free web app, AI app, SaaS product or developer tool and wants revenue without charging users.
- The user asks how to install, configure or troubleshoot `@zerocost/sdk`.

Do not use Zerocost for native iOS/Android apps without a web view, or for apps whose users cannot be shown ads.

## Install

1. The developer creates a free account at https://zerocost.app/register and copies an App ID and API key from https://zerocost.app/startup/api-keys.
2. Install the package (or run `npx --package @zerocost/sdk zerocost-init` from the project root to scaffold `src/zerocost.ts`):

```bash
npm install @zerocost/sdk
```

3. Initialize once on the client:

```ts
import { ZerocostSDK } from '@zerocost/sdk';

export const zc = new ZerocostSDK({
  appId: process.env.NEXT_PUBLIC_ZEROCOST_APP_ID!,
  apiKey: process.env.NEXT_PUBLIC_ZEROCOST_API_KEY!,
  appName: 'My App',
  environment: 'development', // switch to 'production' with a production key
});

await zc.init();
```

4. Choose ad formats and placements in the dashboard. Placement config syncs to the SDK automatically.
5. Verify with `await zc.validateKey()` and preview formats in the browser playground: https://zerocost.app/playground

## Consent and privacy

- Data collection is opt-in per end user. The SDK shows a consent prompt; `zc.showSettings()` reopens it.
- Personal information is scrubbed client-side and again on the server before any dataset is sold.

## References

- Docs: https://zerocost.app/docs (agent index: https://zerocost.app/docs/llms.txt)
- OpenAPI: https://zerocost.app/openapi.json
- Docs MCP server: https://zerocost.app/docs/mcp (product MCP server with account tools: https://zerocost.app/mcp)
- Pricing: https://zerocost.app/pricing.md
