SDK Reference
Complete reference documentation for the @relayplane/sdk package.
This documentation is auto-generated from TypeScript source files and stays in sync with the latest SDK version.
Installation
1npm install @relayplane/sdk2# or3pnpm add @relayplane/sdk4# or5yarn add @relayplane/sdkQuick Start
1import { relay } from '@relayplane/sdk';23// Configure providers4relay.configure({5 providers: {6 openai: { apiKey: process.env.OPENAI_API_KEY! },7 anthropic: { apiKey: process.env.ANTHROPIC_API_KEY! }8 }9});1011// Create and run a workflow12const result = await relay13 .workflow('my-workflow')14 .step('extract', {15 schema: MySchema,16 systemPrompt: 'Extract data from the input'17 })18 .with('openai:gpt-4o')19 .step('summarize')20 .with('anthropic:claude-3.5-sonnet')21 .depends('extract')22 .run({ input: 'Your data here' });2324console.log(result.steps.summarize);Main Exports
relay
The main SDK entry point with methods for creating workflows and configuration.
1import { relay } from '@relayplane/sdk';23// Create a workflow4const workflow = relay.workflow('name');56// Configure globally7relay.configure({ ... });89// Get current config10const config = relay.getConfig();1112// Reset config (for testing)13relay.resetConfig();TypeScript Types
StepConfig
Configuration for a workflow step.
1interface StepConfig {2 /** JSON Schema for structured output */3 schema?: JSONSchema;45 /** System prompt for AI behavior */6 systemPrompt?: string;78 /** User prompt with template variables */9 userPrompt?: string;1011 /** Retry configuration */12 retry?: {13 maxRetries: number;14 backoffMs?: number;15 };1617 /** Custom metadata */18 metadata?: Record; 19}RunOptions
Options for workflow execution.
1interface RunOptions {2 /** Execution mode */3 mode?: 'local' | 'cloud';45 /** Provider configuration overrides */6 providers?: Record; 78 /** Timeout in milliseconds */9 timeout?: number;1011 /** Run metadata */12 metadata?: Record; 1314 /** Abort signal for cancellation */15 signal?: AbortSignal;16}WorkflowResult
Result returned from workflow execution.
1interface WorkflowResult {2 /** Whether workflow succeeded */3 success: boolean;45 /** Step outputs by name */6 steps: Record; 78 /** Final step output */9 finalOutput?: any;1011 /** Error if failed */12 error?: {13 message: string;14 stepName?: string;15 cause?: any;16 };1718 /** Execution metadata */19 metadata: {20 workflowName: string;21 startTime: Date;22 endTime: Date;23 duration: number;24 };25}GlobalConfig
Global SDK configuration.
1interface GlobalConfig {2 /** Provider configurations */3 providers?: Record; 45 /** Telemetry settings */6 telemetry?: {7 enabled: boolean;8 apiEndpoint?: string;9 apiKey?: string;10 };1112 /** Cloud features */13 cloud?: {14 enabled: boolean;15 teamId?: string;16 accessToken?: string;17 };18}ProviderConfig
Configuration for individual providers.
1interface ProviderConfig {2 /** API key for the provider */3 apiKey: string;45 /** Custom base URL */6 baseUrl?: string;78 /** Organization ID (for OpenAI) */9 organization?: string;10}TypeScript Integration
The SDK is fully typed with TypeScript. Use Zod schemas for type-safe structured output:
1import { relay } from '@relayplane/sdk';2import { z } from 'zod';34// Define your schema with Zod5const InvoiceSchema = z.object({6 invoiceNumber: z.string(),7 vendor: z.string(),8 totalAmount: z.number(),9 currency: z.enum(['USD', 'EUR', 'GBP']),10 items: z.array(z.object({11 description: z.string(),12 quantity: z.number(),13 unitPrice: z.number(),14 })),15 dueDate: z.string().optional(),16});1718// TypeScript infers the output type from your schema19type Invoice = z.infer; 2021// Use the schema in your workflow22const result = await relay23 .workflow('invoice-processor')24 .step('extract', { schema: InvoiceSchema })25 .with('openai:gpt-4o')26 .prompt('Extract invoice data from this document: {{input.document}}')27 .run({ document: pdfText });2829// result.steps.extract is typed based on your schema30if (result.success) {31 const invoice: Invoice = result.steps.extract;32 console.log(`Invoice #${invoice.invoiceNumber}`);33 console.log(`Total: ${invoice.totalAmount} ${invoice.currency}`);34}Type-Safe Error Handling
1import { relay, WorkflowResult } from '@relayplane/sdk';23async function processData(input: string): Promise { 4 const result: WorkflowResult = await relay5 .workflow('processor')6 .step('analyze')7 .with('openai:gpt-4o')8 .prompt('Analyze: {{input.data}}')9 .run({ data: input });1011 if (!result.success) {12 // TypeScript knows result.error exists when success is false13 throw new Error(`Step ${result.error?.stepName} failed: ${result.error?.message}`);14 }1516 // TypeScript knows steps exist when success is true17 return result.steps.analyze;18}Generic Workflow Wrapper
1import { relay, WorkflowResult } from '@relayplane/sdk';2import { z } from 'zod';34// Create a typed workflow function5async function runWorkflow( 6 name: string,7 schema: T,8 input: Record 9): Promise> { 10 const result = await relay11 .workflow(name)12 .step('process', { schema })13 .with('openai:gpt-4o')14 .prompt('Process the input according to the schema.')15 .run(input);1617 if (!result.success) {18 throw new Error(result.error?.message);19 }2021 return result.steps.process as z.infer; 22}2324// Usage with full type inference25const SentimentSchema = z.object({26 sentiment: z.enum(['positive', 'negative', 'neutral']),27 confidence: z.number().min(0).max(1),28});2930const sentiment = await runWorkflow('sentiment', SentimentSchema, { text: 'I love this!' });31// sentiment is typed as { sentiment: 'positive' | 'negative' | 'neutral', confidence: number }Version Check
The SDK includes automatic update notifications to help you stay current.
1import { checkForUpdates } from '@relayplane/sdk';23// Check for updates manually4const result = await checkForUpdates();5if (result?.updateAvailable) {6 console.log(`Update available: ${result.current} → ${result.latest}`);7}89// Disable automatic checks10process.env.RELAY_NO_VERSION_CHECK = 'true';1112// Quiet mode (suppress optional updates)13process.env.RELAY_QUIET_VERSION_CHECK = 'true';Environment Variables
The SDK respects these environment variables:
| Variable | Description |
|---|---|
OPENAI_API_KEY | OpenAI API key |
ANTHROPIC_API_KEY | Anthropic API key |
GOOGLE_API_KEY | Google AI API key |
XAI_API_KEY | xAI API key |
OLLAMA_HOST | Ollama server URL (default: http://localhost:11434) |
RELAY_API_HOST | RelayPlane API host (default: https://api.relayplane.com) |
RELAY_NO_VERSION_CHECK | Disable version check notifications |
Supported Models
View the complete list of supported models and their capabilities:
- •
GET /models.json- All models with pricing and capabilities - •
GET /providers.json- Provider configurations
See Also
- •API Reference - Detailed method documentation
- •Quickstart Guide - Get started in 5 minutes
- •Providers Guide - Configure OpenAI, Anthropic, and more
- •Examples - Production-ready workflow examples