Docs/SDK/Quick Start

Quick Start

Install the SDK and start logging AI traffic in under 5 minutes.

1

Install

bash
npm install apptvty
# or
pnpm add apptvty

Node.js ≥ 18 required (uses native fetch).

2

Get credentials

Run the CLI to register your site and write credentials to your env file automatically. No account or email needed — a wallet is created for you.

bash
# Interactive (human)
npx apptvty init

# Non-interactive (agent / CI)
npx apptvty init --domain mysite.com --framework nextjs --non-interactive

This writes APPTVTY_API_KEY and APPTVTY_SITE_ID to .env.local (Next.js) or .env (Express). CLI reference → or Programmatic Onboarding →

3

Add to your app

Next.js (App Router) full guide →

middleware.ts
import { withApptvty } from 'apptvty/nextjs';

export default withApptvty({
  apiKey: process.env.APPTVTY_API_KEY!,
  siteId: process.env.APPTVTY_SITE_ID!,
});

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};
app/query/route.ts
import { createNextjsQueryHandler } from 'apptvty/nextjs';

export const GET = createNextjsQueryHandler({
  apiKey: process.env.APPTVTY_API_KEY!,
  siteId: process.env.APPTVTY_SITE_ID!,
});

Express full guide →

server.ts
import express from 'express';
import { createExpressMiddleware, createExpressQueryHandler } from 'apptvty/express';

const app = express();
const config = {
  apiKey: process.env.APPTVTY_API_KEY!,
  siteId: process.env.APPTVTY_SITE_ID!,
};

app.use(createExpressMiddleware(config));
app.get('/query', createExpressQueryHandler(config));
4

Verify it's working

Open your dashboard (the URL printed by the CLI), send a test request with a known AI user-agent, and watch the request appear in your analytics within seconds.

bash
# Simulate a GPTBot request
curl -A 'GPTBot/1.1' https://yoursite.com/

# Test the query endpoint
curl 'https://yoursite.com/query?q=What+does+this+site+do'

Configuration

All middleware and handler functions accept an ApptvtyConfig object.

FieldTypeDefaultDescription
apiKeystringRequired. Your API key (ak_live_...)
siteIdstringRequired. Your site ID (site_...)
baseUrlstring?https://api.apptvty.comAPI base URL override
batchSizenumber?50Log entries per flush
flushIntervalnumber?5000ms between auto-flushes
debugboolean?falsePrint API errors to console
queryPathstring?/queryPath of the AEO endpoint on your domain