Skip to content
reaatechREAATECH

@reaatech/prompt-version-control-server

pending npm

A Hono app that exposes a REST API for Git-like version control of AI prompts, with eval-gated staging-to-production promotion, A/B traffic splitting, metrics ingestion, and webhook subscriptions, backed by Prisma and PostgreSQL.

@reaatech/prompt-version-control-server

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Prompt Version Control API server providing Git-like versioning for AI prompts with eval-gated promotion, A/B deployment, metrics collection, and webhook integrations. Built on Hono 4 with Prisma and PostgreSQL.

Installation

terminal
npm install @reaatech/prompt-version-control-server
# or
pnpm add @reaatech/prompt-version-control-server

Feature Overview

  • Prompt CRUD — create, read, update, and archive prompts with automatic version numbering
  • Version management — store and track prompt versions with SHA-256 checksums for deduplication
  • Tag-based lifecycle — resolve versions by draft, staging, and production tags
  • Evaluation gates — block staging→production promotion on eval harness results
  • A/B deployments — serve multiple versions with weighted traffic splitting and sticky sessions
  • Semantic diffing — compare versions with line-level diffs and semantic impact scoring
  • Metrics ingestion — track per-version cost, latency, and quality metrics
  • Promotion workflows — promote/rollback production with audit trails
  • Webhook subscriptions — notify external systems on version creation, tag changes, and evaluations
  • Structured logging — Pino-based JSON logging with automatic pretty-printing in development
  • Prometheus metrics — built-in /metrics endpoint for monitoring
  • API key auth — scoped API keys with HMAC verification and audit logging
  • Swagger UI — OpenAPI 3.0 spec served at /api/v1/docs

Quick Start

Development

terminal
# Set up environment
cp .env.example .env
 
# Install dependencies
pnpm install
 
# Generate Prisma client
pnpm --filter @reaatech/prompt-version-control-server db:generate
 
# Run migrations
pnpm --filter @reaatech/prompt-version-control-server db:migrate
 
# Seed the database
pnpm --filter @reaatech/prompt-version-control-server db:seed
 
# Start development server with hot reload
pnpm --filter @reaatech/prompt-version-control-server dev

Programmatic

typescript
import { app } from "@reaatech/prompt-version-control-server";
import { serve } from "@hono/node-server";
 
serve({ fetch: app.fetch, port: 3000 }, (info) => {
  console.log(`Server running on http://localhost:${info.port}`);
});

API Reference

Infrastructure Endpoints

MethodPathDescription
GET/healthHealth check — returns { status: "ok", timestamp }
GET/readyReadiness check — returns { status: "ready" }
GET/metricsPrometheus text-format metrics
GET/api/v1/docsSwagger UI
GET/api/v1/docs/openapi.yamlRaw OpenAPI 3.0 spec

All API routes are prefixed with /api/v1 and require Authorization: Bearer <api-key> unless noted.

Prompts

MethodPathDescription
GET/api/v1/promptsList prompts (paginated: ?limit=20&cursor=...)
POST/api/v1/promptsCreate prompt
GET/api/v1/prompts/:idGet prompt by ID
PUT/api/v1/prompts/:idUpdate prompt
DELETE/api/v1/prompts/:idArchive prompt
GET/api/v1/prompts/:id/versionsList versions for prompt (paginated)
POST/api/v1/prompts/:id/versionsCreate version (auto-increments number)
GET/api/v1/prompts/:id/versions/:vidGet specific version
GET/api/v1/prompts/:id/productionGet production-tagged version
GET/api/v1/prompts/:id/diffDiff two versions (?fromVersion=X&toVersion=Y)

Tags

MethodPathDescription
GET/api/v1/prompts/:id/tagsList tags for prompt
POST/api/v1/prompts/:id/tags/:nameSet tag to a version ({ versionId } in body)
GET/api/v1/prompts/:id/tags/:nameGet tag details
DELETE/api/v1/prompts/:id/tags/:nameRemove tag

Tag names: draft, staging, production. Only one version can hold a given tag at a time.

Promotions

MethodPathDescription
POST/api/v1/prompts/:id/promotePromote staging → production (gated by eval)
POST/api/v1/prompts/:id/promote/overrideForce-promote a specific version ({ versionId } in body)
POST/api/v1/prompts/:id/rollbackRollback production to previous version

The promote endpoint checks the evaluation gate: if the staging version has failed evaluations, the promotion is blocked.

Evaluations

MethodPathDescription
POST/api/v1/evaluations/webhookReceive eval harness webhook (public, HMAC-authenticated)
POST/api/v1/evaluations/triggerTrigger evaluation ({ versionId } in body)
GET/api/v1/evaluations/versions/:versionIdList evaluations for a version
GET/api/v1/evaluations/versions/:versionId/gateGet promotion gate status

Metrics

MethodPathDescription
POST/api/v1/metrics/ingestIngest metrics (array of metric objects in body)
GET/api/v1/metrics/versions/:versionIdGet metrics for version (?hours=24 optional)
GET/api/v1/metrics/prompts/:promptIdGet metrics for prompt (?hours=24 optional)

Metric types: cost, latency, quality.

Deployments

MethodPathDescription
POST/api/v1/deploymentsCreate deployment with weighted variants
GET/api/v1/deploymentsList deployments (?promptId= filter optional)
GET/api/v1/deployments/:id/resolveResolve version for session (?sessionId=)
PUT/api/v1/deployments/:idUpdate deployment status (active/paused/archived)

Render

MethodPathDescription
POST/api/v1/prompts/:id/versions/:number/renderRender specific version with variables
POST/api/v1/prompts/:id/renderRender production version with variables

Both accept { variables: Record<string, unknown> } in the body and return the rendered output with variable usage metadata.

Webhooks

MethodPathDescription
POST/api/v1/webhooksCreate webhook subscription
GET/api/v1/webhooksList subscriptions
DELETE/api/v1/webhooks/:idDelete subscription
POST/api/v1/webhooks/:id/testTest delivery

Middleware Stack

All API routes pass through:

MiddlewareDescription
requestIdMiddlewareAssigns requestId to every request context
compress()gzip/deflate response compression
cors()Configurable via CORS_ALLOWED_ORIGINS env var
rateLimit()100 requests per 60-second window per IP
metricsMiddlewarePrometheus metrics collection
authBearer API key verification via HMAC

Environment Variables

VariableRequiredDefaultDescription
DATABASE_URLYesPostgreSQL connection string
REDIS_URLYesRedis connection string
NODE_ENVNodevelopmentEnvironment (development enables pretty logging)
PORTNo3000Server listen port
LOG_LEVELNoinfoPino log level
JWT_SECRETNoHMAC pepper for API key hashing
API_KEY_PEPPERNoAdditional pepper for API key HMAC
EVAL_WEBHOOK_SECRETNoHMAC secret for eval webhook verification
CORS_ALLOWED_ORIGINSNo*CORS allowed origins

Usage Patterns

Create a Prompt with Versions

terminal
# Create a prompt
curl -X POST http://localhost:3000/api/v1/prompts \
  -H "Authorization: Bearer pvc_your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "customer-support",
    "template": "You are a helpful support agent. Help with: {{issue}}"
  }'
 
# Create a version
curl -X POST http://localhost:3000/api/v1/prompts/<promptId>/versions \
  -H "Authorization: Bearer pvc_your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "You are a senior support agent. Help with: {{issue}}"
  }'
 
# Tag as production
curl -X POST http://localhost:3000/api/v1/prompts/<promptId>/tags/production \
  -H "Authorization: Bearer pvc_your-api-key" \
  -H "Content-Type: application/json" \
  -d '{ "versionId": "<versionId>" }'

Render a Prompt with Variables

terminal
curl -X POST http://localhost:3000/api/v1/prompts/<promptId>/render \
  -H "Authorization: Bearer pvc_your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "variables": { "issue": "I cannot log in to my account" }
  }'

A/B Deployment

terminal
curl -X POST http://localhost:3000/api/v1/deployments \
  -H "Authorization: Bearer pvc_your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "promptId": "<promptId>",
    "variants": [
      { "versionId": "<versionA>", "weight": 90 },
      { "versionId": "<versionB>", "weight": 10 }
    ]
  }'
 
# Resolve for a session
curl "http://localhost:3000/api/v1/deployments/<deploymentId>/resolve?sessionId=user-123" \
  -H "Authorization: Bearer pvc_your-api-key"

License

MIT