Skip to main content

JavaScript SDK

The official Perf SDK for JavaScript and TypeScript provides a type-safe, feature-rich client for the Perf API with streaming support, automatic retries, and comprehensive error handling.

Installation

Quick Start

Configuration

Chat Completions

Basic Request

With Cost Control

Request Options

Streaming

Stream responses for real-time output:

Stream to String Helper

Error Handling

The SDK provides typed error classes for different error scenarios:

Error Properties

All PerfError instances have these properties:

Rate Limit Error

TypeScript Support

The SDK is written in TypeScript and exports all types:

Response Types

ChatResponse

StreamChunk

Examples

Multi-turn Conversation

JSON Output

React Hook Example

Requirements

  • Node.js 18.0.0 or higher
  • TypeScript 5.0+ (for TypeScript users)

Support