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
AllPerfError instances have these properties:
| Property | Type | Description |
|---|---|---|
code | string | Machine-readable error code |
message | string | Human-readable description |
status | number | HTTP status code |
requestId | string | Unique request ID for debugging |
isRetryable | boolean | Whether safe to retry |
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
- npm: @perf_technology/sdk
- Documentation: docs.withperf.pro
- Email: [email protected]