Skip to main content

Overview

This guide provides comprehensive JavaScript and TypeScript examples for integrating with the SundayPyjamas AI Suite API. All examples include proper error handling, type safety, and production-ready patterns.
Examples work in both Node.js and browser environments. TypeScript definitions are included for better development experience.

Installation

Basic Setup

No additional packages are required for basic usage with modern environments:

Environment Variables

Create a .env file for secure configuration:

TypeScript Configuration

Basic Examples

Simple Chat Request

Streaming Responses

Real-time Streaming

React Chat Component

Complete Chat Interface

Content Generation

Blog Post Generator

Error Handling

Robust Error Handling

Node.js Server Example

Express.js API Server

Browser Usage

Frontend Integration

Testing

Unit Tests

Beyond Chat: Other APIs

See the full Agents API reference.
See the full Image API reference.
See the full Artifacts API reference.

Next Steps

Python Examples

Explore comprehensive Python implementations with async support

cURL Examples

Command-line examples for testing and automation

Rate Limits

Learn about optimization and usage tracking

Error Handling

Master robust error handling patterns
All JavaScript examples can be easily adapted for TypeScript by adding type annotations. The examples shown include full TypeScript support for better development experience.