Back to Puter

README

src/puter-js/README.md

26.083.6 KB
Original Source
<h3 align="center">Puter.js</h3> <p align="center"> <a href="https://developer.puter.com" target="_blank">Learn More</a> · <a href="https://docs.puter.com" target="_blank">Docs</a> · <a href="https://developer.puter.com/tutorials">Tutorials</a> · <a href="https://github.com/Puter-Apps/">Examples</a> · <a href="https://twitter.com/HeyPuter">X</a> </p>

Puter.js gives you auth, cloud storage, database, AI, and more through a single JavaScript library. It is the go-to backend for AI-generated apps.

There is nothing to configure, no API keys, no infrastructure to set up, whether you write the code yourself or have your AI tool do it. Tools like Claude Code, Codex, OpenCode, Lovable, and Replit can generate complete, production-ready apps in a single shot with fewer AI tokens.

Installation

NPM:

sh
npm install @heyputer/puter.js

CDN:

Include Puter.js directly in your HTML via CDN in the <head> section:

html
<script src="https://js.puter.com/v2/"></script>

Usage

Browser

ES Modules

js
import {puter} from '@heyputer/puter.js';
// or
import puter from '@heyputer/puter.js';
// or 
import '@heyputer/puter.js'; // puter will be available globally

CommonJS

js
const {puter} = require('@heyputer/puter.js');
// or
const puter = require('@heyputer/puter.js');
// or
require('@heyputer/puter.js'); // puter will be available globally

Node.js (with Auth Token)

js
const {init} = require("@heyputer/puter.js/src/init.cjs"); // NODE JS ONLY
// or
import {init} from "@heyputer/puter.js/src/init.cjs";

const puter = init(process.env.puterAuthToken); // uses your auth token
const puter2 = init(process.env.puterAuthToken2); // use some other auth token

Node.js (with Auth Token + Web Login)

js
const {init, getAuthToken} = require("@heyputer/puter.js/src/init.cjs");
// or
import {init, getAuthToken} from "@heyputer/puter.js/src/init.cjs";

const authToken = await getAuthToken(); // performs browser based auth and retrieves token (requires browser)
const puter = init(authToken); // uses your auth token

Usage Example

After importing, you can use the global puter object:

js
// Print a message
puter.print('Hello from Puter.js!');

// Chat with GPT-5 nano
puter.ai.chat('What color was Napoleon\'s white horse?').then(response => {
  puter.print(response);
});

Starter Templates

You can also use one of the following templates:

Setting Custom Origins

By default puter.js uses the official Puter API and GUI origins. You can customize these origins by setting global variables before importing the SDK like so:

js
// For API origin
globalThis.PUTER_API_ORIGIN = 'https://custom-api.puter.com';
// For GUI origin
globalThis.PUTER_ORIGIN = 'https://custom-gui.puter.com';

import {puter} from '@heyputer/puter.js'; // or however you import it for your env

Documentation & Community

License

Apache-2.0