Skip to content
/ sdk Public

Dead-simple prompt versioning and A/B testing for Anthropic and OpenAI

License

Notifications You must be signed in to change notification settings

stewrd-dev/sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@stewrd/sdk

Dead-simple prompt versioning and A/B testing for Anthropic and OpenAI.

npm version License: MIT

Installation

npm install @stewrd/sdk
# or
pnpm add @stewrd/sdk
# or
yarn add @stewrd/sdk

Quick Start

import { PromptSDK } from '@stewrd/sdk';

const sdk = new PromptSDK({ apiKey: 'your-stewrd-api-key' });

// Simple usage - version tracking
const response = await sdk.run('user-onboarding-v2', {
  model: 'claude-sonnet-4-5',
  input: 'Hello! I need help getting started.',
});

console.log(response.content);

A/B Testing

Split traffic between prompt variants and measure real performance:

const response = await sdk.run('user-onboarding', {
  model: 'claude-sonnet-4-5',
  input: userMessage,
  variants: {
    'control': {
      weight: 50,
      systemMessage: 'You are a friendly onboarding assistant.',
    },
    'experiment': {
      weight: 50,
      systemMessage: 'You are a concise onboarding expert.',
    },
  },
});

console.log(`Used variant: ${response.variant}`);
console.log(response.content);

Features

  • Prompt Versioning - Track every prompt change, roll back when needed
  • A/B Testing - Split traffic between variants, measure real performance
  • Multi-Provider - Works with Anthropic (Claude) and OpenAI (GPT)
  • Usage Analytics - Token usage, latency, cost tracking per variant
  • TypeScript First - Fully typed with great DX
  • Retry Logic - Built-in exponential backoff for reliability
  • Lightweight - Minimal dependencies, fast startup

Configuration

const sdk = new PromptSDK({
  apiKey: 'sk_...', // Required: Your stewrd API key
  baseUrl: 'https://api.stewrd.dev', // Optional: API endpoint
  debug: false, // Optional: Enable debug logging
  timeout: 30000, // Optional: Request timeout in ms
  retry: {
    maxRetries: 3, // Optional: Max retry attempts
    baseDelay: 1000, // Optional: Initial retry delay
    maxDelay: 10000, // Optional: Max retry delay
    exponentialBackoff: true, // Optional: Use exponential backoff
  },
});

API Reference

sdk.run(promptName, options)

Execute a prompt with optional versioning and A/B testing.

Parameters:

Option Type Required Description
model string Yes Model identifier (e.g., 'claude-sonnet-4-5', 'gpt-4o')
input string Yes User message/input
systemMessage string No System prompt
variants object No A/B testing configuration
parameters object No Model parameters (temperature, max_tokens, etc.)
metadata object No Custom metadata to attach

Response:

interface PromptResponse {
  content: string; // Generated response text
  variant?: string; // Selected variant (if A/B testing)
  provider: 'anthropic' | 'openai'; // Provider used
  model: string; // Model that was used
  usage?: {
    inputTokens: number;
    outputTokens: number;
    totalTokens: number;
  };
  latencyMs: number; // Response time in milliseconds
  runId?: string; // Unique run identifier
}

sdk.getAnalytics(promptName, options?)

Fetch analytics for a prompt.

const analytics = await sdk.getAnalytics('user-onboarding', {
  startDate: new Date('2024-01-01'),
  endDate: new Date(),
  variant: 'experiment', // Optional: filter by variant
});

Supported Models

Anthropic:

  • claude-opus-4-5 / claude-opus-4-5-20251101
  • claude-sonnet-4-5 / claude-sonnet-4-5-20251101
  • claude-3-5-sonnet / claude-3-5-sonnet-20241022
  • claude-3-5-haiku / claude-3-5-haiku-20241022

OpenAI:

  • gpt-4o / gpt-4o-2024-08-06
  • gpt-4o-mini
  • gpt-4-turbo
  • gpt-3.5-turbo

Environment Variables

For local development, set your provider API keys:

ANTHROPIC_API_KEY=your-anthropic-key
OPENAI_API_KEY=your-openai-key

TypeScript Support

Fully typed with TypeScript. Import types as needed:

import type {
  PromptSDK,
  PromptSDKConfig,
  PromptResponse,
  RunOptions,
  PromptVariant,
  RetryConfig,
} from '@stewrd/sdk';

Links

License

MIT - see LICENSE for details.

About

Dead-simple prompt versioning and A/B testing for Anthropic and OpenAI

Resources

License

Stars

Watchers

Forks

Packages

No packages published