Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nextjs/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Set in your Vercel project environment variables.
# For local dev: add to .env.local (never commit this file)
#
# The app reads KAK_API_KEY or KAKUNIN_API_KEY. The Vercel Marketplace
# integration injects KAK_API_KEY automatically; for local dev set either.
KAKUNIN_API_KEY=kak_live_...
2 changes: 1 addition & 1 deletion nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Full-stack example: agent registration, certificate issuance, and middleware-lev

## What this covers

- `lib/kakunin.ts` — singleton SDK init (reads `KAK_API_KEY` from env)
- `lib/kakunin.ts` — singleton SDK init (reads `KAK_API_KEY` or `KAKUNIN_API_KEY` from env)
- `app/api/v1/agents/route.ts` — register + certify an agent via POST
- `middleware.ts` — enforce cert serial on all `/api/agent/*` routes

Expand Down
18 changes: 13 additions & 5 deletions nextjs/lib/kakunin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import Kakunin from '@kakunin/sdk';

// Singleton — reuse across requests in the same serverless function instance.
// KAKUNIN_API_KEY is set in your Vercel project environment variables.
// Use kak_live_... for production, kak_test_... for sandbox.
export const kkn = new Kakunin({
apiKey: process.env.KAKUNIN_API_KEY!,
});
// The API key comes from your environment. The Vercel Marketplace integration
// injects KAK_API_KEY; local dev / the Deploy button use KAKUNIN_API_KEY. We
// accept either so both paths work. Use kak_live_... for production,
// kak_test_... for sandbox.
const apiKey = process.env.KAK_API_KEY ?? process.env.KAKUNIN_API_KEY;
if (!apiKey) {
throw new Error(
'Missing Kakunin API key. Set KAKUNIN_API_KEY (or KAK_API_KEY via the ' +
'Vercel Marketplace integration). Get one at https://kakunin.ai/dashboard/api-keys',
);
}

export const kkn = new Kakunin({ apiKey });
Loading