Skip to main content
The PraisonAI TypeScript SDK runs in any JavaScript runtime — not just Node. Pass the API key through the Agent config, and the same code that runs on your server runs inside a Tauri app, a React Native mobile app, a browser webview, Deno, Bun, or a Cloudflare Worker.

Quick Start

1

Create an agent in a browser bundle

Pass the API key explicitly — a browser bundle has no process.env.
Never bundle a raw API key into a shipped browser or mobile build. Route requests through your own backend or an ephemeral-token endpoint. This example assumes a trusted-device / desktop / dev context.

Choosing Where to Run

Pick the runtime that matches how your agent ships.

What Changed

The Agent constructor now works on runtimes without a process global. Previously the constructor read process.env.OPENAI_MODEL_NAME, PRAISONAI_MODEL, PRAISON_VERBOSE, and PRAISON_PRETTY directly. On any runtime without a process global (Tauri webview, React Native, plain browser), the very first new Agent(...) threw ReferenceError: process is not defined — before your code ever ran. Now those reads go through an internal getEnv() helper that returns undefined when there is no process. Constructors succeed, defaults apply (gpt-4o-mini, verbose on, pretty off), and any explicit config value still wins. Streaming also survives: the default token sink (writeTokenToStdout) no-ops when process.stdout is unavailable, so agent.start() and agent.stream() no longer die on the first token in a webview.

Runtime Interaction Flow

A single agent call streams tokens straight into your UI.

Passing API Keys Per Runtime

Read the key where each runtime keeps it, then pass it to the Agent.

Minimal Tauri Example

Read the key in Rust, hand it to the renderer, and construct the agent.

Minimal React Native Example

Fetch an ephemeral token from your backend, then run the agent on-device.

Streaming Without stdout

Use stream() and render each chunk into the UI instead of the terminal.
If you call agent.start(prompt) with no onToken handler in a browser / webview, the tokens are silently discarded (they cannot be written to process.stdout). Use stream() or pass onToken to render them.

Best Practices

Proxy every request or mint an ephemeral token from your own backend. A key bundled into a browser or mobile build is public.
The gpt-4o-mini default only applies when the env is unreachable and you passed no llm. Set llm so behaviour is identical across every runtime.
The default token sink is silent when there is no stdout. Use stream() (or pass onToken to start()) to render tokens live in the UI.
Pass an AbortSignal through SimpleAgentConfig.signal or stream(prompt, { signal }), and abort it when the user leaves the screen to stop the provider request.

Troubleshooting

You’re on a pre-fix build. Update praisonai to the release that ships the getEnv() guard.
You didn’t pass an apiKey and the runtime has no env. Check your Agent config.
You called start() without onToken. Use stream() or supply an onToken callback.

TypeScript SDK

TypeScript SDK overview

Agent

Agent overview

Streaming

Streaming responses

Providers

LLM providers