novatar
v0.2.0
Published
Deterministic generative SVG avatar engine for humans and AI agents. CLI + MCP + React + HTTP, zero-config npx.
Maintainers
Readme
novatar
Deterministic generative SVG avatars — one package, two engines, built for humans and AI agents.
The same seed always produces the same avatar: byte-identical output across machines, runtimes, and replays.
npx novatar <seed>— zero-config CLI exporting SVG · PNG · WebP stills and animated SVG · APNG · GIFnovatar-mcp— MCP server for AI agents (Claude, Notion AI agents, Cursor, …)novatar/server— Web-standard HTTP handler (Vercel, Workers, Bun, Deno)novatar/react— React components (static + animated)- Pure-JS/WASM encoders, no native builds required (WebP uses optional prebuilt sharp). No prompts. No network.
Two engines, one identity model:
| Engine | Catalog |
| ------------ | ----------------------------------------------------------------- |
| avatars | 21 variants · 4 families (gradient, fluid, classic, paletteless) |
| duo | 21 shapes × 22 expressions × 6 generative backgrounds |
Quick start (CLI)
npx novatar justin > justin.svg # SVG to stdout
npx novatar justin --engine duo --shape cat --expression loving
npx novatar justin --engine avatars --variant triton --json
npx novatar justin --png --size 512 --out avatar.png # still PNG
npx novatar justin --webp --quality 95 --out avatar.webp # still WebP
npx novatar justin --animate --out animated.svg # animated SVG (SMIL, loops forever)
npx novatar justin --gif --size 256 --out avatar.gif # animated GIF
npx novatar justin --apng --size 256 --out avatar.png # animated PNG with alpha
npx novatar justin --gif --datauri # ready-to-embed data:image/gif URI
npx novatar --batch alice,bob,carol --apng --out 'team/{seed}.png' # batch animations
npx novatar --random --count 12 --json # 12 random avatars as a JSON array
npx novatar --list # machine-readable catalogRead seeds from stdin — one per line; more than one line is a batch:
echo "user-42" | npx novatar - --json
git log --format=%an | sort -u | npx novatar - --png --out 'team/{seed}.png'Full CLI reference: npx novatar --help. Agent-oriented cookbook: AGENTS.md.
Install
npm install novatarWorks in Node ≥ 18, browser bundlers, Vercel Functions (Node & Edge for SVG), Cloudflare Workers, Bun, Deno.
Programmatic API
Unified — createNovatar
import { createNovatar } from 'novatar'
const svg = createNovatar({ seed: 'justin', engine: 'duo', shape: 'cat', expression: 'loving' })
const json = createNovatar({ seed: 'justin', engine: 'avatars', variant: 'triton', format: 'json' })
// { seed, engine, svg, dataUri, variant, circle, effect, animate }engine: 'auto'(default) picks deterministically from the seed. Aliases:duo,emoji,avatar,art.- Engine-specific options are ignored by the other engine, so one call shape covers both.
Engine compat APIs
The full upstream surfaces are preserved for drop-in migration:
import { createAvatar, resolveVariant } from 'novatar' // avatars-engine API
import { createDuo, resolveLayout, renderLayout, DuoEngine } from 'novatar' // duo-engine APIIntrospection & palettes
import { listNovatarStyles, generatePalette } from 'novatar'
listNovatarStyles() // { engines: [{ id, variants | shapes, expressions, backgrounds }] }
listNovatarStyles('duo')
generatePalette('justin') // { seed, colors: [ '#..', ×5 ] } — deterministicRaster, WebP & animation exports
import { renderPng, renderPngDataUri, renderWebp } from 'novatar/raster'
import { renderAnimatedSvg, renderAnimatedGif, renderAnimatedApng } from 'novatar'
const png = await renderPng(svg, { width: 512 }) // Uint8Array (resvg WASM)
const webp = await renderWebp(svg, { width: 512, quality: 95 }) // optional sharp
const animatedSvg = renderAnimatedSvg({ seed: 'justin', shape: 'cat' }) // SMIL, loops forever
const gif = await renderAnimatedGif({ seed: 'justin', width: 256, fps: 12 })
const apng = await renderAnimatedApng({ seed: 'justin', width: 256 }) // full alphaAnimated exports reproduce the <Duo /> motion (autonomous blinking
- gaze drift, optional
wobble) from one frame solver, so every format moves identically. Loops are locked to the 4.7 s blink cycle —durationis snapped to a multiple of it so GIF/APNG wraps are seamless. GIF composites transparency onto agifBackgroundmatte (1-bit alpha); APNG and animated SVG keep full alpha. Animated raster exports use the duo engine (the avatars engine's CSS animation cannot be time-sampled by rasterizers).
React
import { Novatar, Avatar, Duo } from 'novatar/react'
<Novatar seed="justin" engine="duo" shape="cat" size={64} />
<Avatar name="orion" variant={/* 'triton' | family | 'all' */ 'fluid'} animate />
<Duo seed="justin" shape="cat" expression="loving" animate animOnClick animOnHover /><Duo /> is the fully alive experience: breathing, gaze drift, blinks,
hover/click reactions, reduced-motion aware. <Avatar /> and <Novatar /> render
static markup (SSR-safe). React 18+ is an optional peer dependency — the core
never imports it.
HTTP API (Vercel & friends)
// app/api/avatar/[[...route]]/route.ts
import { createNovatarHandler } from 'novatar/server'
export const GET = createNovatarHandler({ base: '/api/avatar' })<img src="https://your-app.vercel.app/api/avatar/orion.svg" />
<img src="https://your-app.vercel.app/api/avatar/justin.png?engine=duo&shape=cat&expression=loving" />Deterministic responses ship with Cache-Control: immutable. See
examples/vercel-api for a deployable project.
Astro
First-class — and no React required. The core generates plain SVG strings, so avatars render at build time with zero client-side JavaScript (even the animated SVG blinks via SMIL, no hydration):
---
import { createNovatar, renderAnimatedSvg } from 'novatar'
const avatar = createNovatar({ seed: 'justin', engine: 'duo', shape: 'cat', expression: 'loving' })
const animated = renderAnimatedSvg({ seed: 'hero', shape: 'ufo' })
---
<Fragment set:html={avatar} />
<Fragment set:html={animated} />The HTTP handler drops into an Astro endpoint as a Web-standard
Request → Response function (all formats: svg / png / webp / gif / apng /
json, plus ?animate=true):
// src/pages/api/avatar/[...route].ts
import type { APIRoute } from 'astro'
import { createNovatarHandler } from 'novatar/server'
export const prerender = false // on-demand route (Astro is static by default)
const handler = createNovatarHandler({ base: '/api/avatar' })
export const GET: APIRoute = (ctx) => handler(ctx.request)astro dev serves the endpoint as-is; astro build needs any adapter (e.g.
@astrojs/node) for on-demand routes. The React components from
novatar/react also work through @astrojs/react when you want interactive
islands (<Duo client:load />). Complete working project:
examples/astro.
Style catalog
avatars engine — 21 variants
All tiles use the same seed (orion), so palette differences come from the variants themselves.
duo engine — 21 shapes
Seed novatar, rotating expressions to show a little life:
22 expressions
Same seed and shape — only the expression changes:
6 generative backgrounds
Every catalog accepts all for a deterministic pick from the seed. Query the live
catalog anywhere: npx novatar --list or listNovatarStyles().
MCP server (AI agents)
Expose novatar to any MCP client — three tools: novatar_generate,
novatar_list_styles, novatar_palette.
// e.g. Claude Desktop: claude_desktop_config.json
{
"mcpServers": {
"novatar": { "command": "npx", "args": ["-y", "novatar", "--mcp"] }
}
}Any stdio MCP client works: novatar-mcp is also a standalone bin. Setup recipes
for Notion AI agents and sandbox environments: AGENTS.md.
Determinism & versioning
- Same seed + same options → byte-identical SVG/PNG, on every machine, forever within a major version.
- Output parity with the adapted upstream sources is enforced by the contract tests (
npm test). - Breaking visual changes will bump the major version.
Development
npm install
npm run build # tsup → dist (esm + cjs + types)
npm test # contract tests: engines, upstream parity, CLI, MCP, HTTPCredits & license
MIT © 2026 Justin Cheu.
Avatar engines and palette data adapted from the delightful MIT-licensed work by SpaceUI. PNG rasterization by resvg-wasm. Agent logos from thesvg.org; all trademarks belong to their owners.
