The Puter.js AI feature allows you to integrate artificial intelligence capabilities into your applications.
You can use AI models from various providers to perform tasks such as chat, text-to-image, image-to-text, and text-to-speech conversion. And with the User Pays Model, you don't have to set up your own API keys and top up credits, because users cover their own AI costs.
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat(`What is life?`, { model: "gpt-5-nano" }).then(puter.print);
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Generate an image of a cat using the default model and quality. Please note that testMode is set to true so that you can test this code without using up API credits.
puter.ai.txt2img('A picture of a cat.', true).then((image)=>{
document.body.appendChild(image);
});
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.img2txt('https://cdn.handwrytten.com/www/2020/02/home-hero-photo2%402x.png').then(puter.print);
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="play">Speak!</button>
<script>
document.getElementById('play').addEventListener('click', ()=>{
puter.ai.txt2speech(`Hello world! Puter is pretty amazing, don't you agree?`).then((audio)=>{
audio.play();
});
});
</script>
</body>
</html>
These AI features are supported out of the box when using Puter.js:
puter.ai.chat()
- Chat with AI models like Claude, GPT, and othersputer.ai.txt2img()
- Generate images from text descriptionsputer.ai.img2txt()
- Extract text from images (OCR)puter.ai.txt2speech()
- Convert text to speechYou can see various Puter.js AI features in action from the following examples: