Node.js SDK

High-performance integration for Node.js and Edge environments.

Installation

The PromptForge Server SDK is the fastest way to integrate with our engine. It handles token caching, retries, and high-performance routing out of the box.

npm install promptforge-server-sdk

Initialization

typescript
import { PromptForgeClient } from 'promptforge-server-sdk';

// Initialize with your secret API key
const pf = new PromptForgeClient({
  apiKey: process.env.PROMPTFORGE_API_KEY,
  timeoutMs: 30000, // Optional 30s timeout
});

Executing Prompts

The execute method is your primary interface. It accepts a version ID and dynamic variables.

typescript
async function runPrompt() {
  const result = await pf.execute({
    versionId: 'c123-abc-456', // Unique prompt version ID
    variables: {
      topic: 'Quantum Computing',
      difficulty: 'Expert'
    }
  });

  if (result.success) {
    console.log(result.data); // The generated response
    console.log(`Latency: ${result.meta.latencyMs}ms`);
  }
}

Return Types

typescript
interface PromptResponse {
  success: boolean;
  data: string;
  meta: {
    model: string;
    latencyMs: number;
    cached: boolean;
    tokens?: {
      input: number;
      output: number;
    }
  }
}

Ready to build?

Check out our pre-built examples to see how to implement common patterns like A/B testing, streaming, and advanced prompt versioning.

Explore SDK Examples