Skip to Content
Javascript (2)

Last Updated: 4/8/2026


JavaScript Client API

The Pie JavaScript client library provides a type-safe interface for Node.js and browser environments.

Installation

npm install @pie-project/client

Quick Start

import { PieClient } from '@pie-project/client'; const client = new PieClient('http://localhost:8080'); // Run an inferlet const result = await client.run({ inferlet: 'std/text-completion', args: { prompt: 'Once upon a time' } }); console.log(result);

API Reference

PieClient

Main client class:

const client = new PieClient(baseUrl: string, options?: ClientOptions);

Methods

run()

Run an inferlet:

const result = await client.run({ inferlet: string, args: Record<string, any>, timeout?: number });

submit()

Submit for async execution:

const jobId = await client.submit({ inferlet: string, args: Record<string, any> });

getResult()

Get job result:

const result = await client.getResult(jobId: string);

uploadInferlet()

Upload custom inferlet:

await client.uploadInferlet({ name: string, wasmBuffer: Buffer | Uint8Array });

Examples

Basic Usage

import { PieClient } from '@pie-project/client'; const client = new PieClient('http://localhost:8080'); const result = await client.run({ inferlet: 'std/text-completion', args: { prompt: 'Explain machine learning:', max_tokens: 100 } }); console.log(result);

Custom Inferlet

import fs from 'fs'; // Upload inferlet const wasmBuffer = fs.readFileSync('./my_inferlet.wasm'); await client.uploadInferlet({ name: 'my-inferlet', wasmBuffer }); // Run it const result = await client.run({ inferlet: 'my-inferlet', args: { input: 'test' } });

Streaming Results

const stream = await client.stream({ inferlet: 'std/text-completion', args: { prompt: 'Tell me a story' } }); for await (const chunk of stream) { process.stdout.write(chunk); }

Error Handling

try { const result = await client.run({ inferlet: 'my-inferlet', args: { prompt: 'test' } }); } catch (error) { if (error instanceof PieError) { console.error('Pie error:', error.message); } }

TypeScript Support

Full TypeScript definitions included:

interface RunOptions { inferlet: string; args: Record<string, any>; timeout?: number; } interface RunResult { output: string; metadata?: Record<string, any>; }

Next Steps