Getting Started
Just include the script below in your HTML to start using Puter.js:
<script src="https://js.puter.com/v2/"></script>
Example 1: Text Generation (GPT-4o)
Use GPT-4o for text generation:
puter.ai.chat("What are the benefits of exercise?")
.then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("What are the benefits of exercise?")
.then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 2: Generate Images with DALL·E 3
Generate images with the puter.ai.txt2img()
function:
puter.ai.txt2img("A futuristic cityscape at night")
.then(imageElement => {
document.body.appendChild(imageElement);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.txt2img("A futuristic cityscape at night")
.then(imageElement => {
document.body.appendChild(imageElement);
});
</script>
</body>
</html>
Example 3: Analyze Images with GPT-4o Vision
Use GPT-4o Vision to analyze an image:
puter.ai.chat(
"What do you see in this image?",
"https://assets.puter.site/doge.jpeg"
).then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat(
"What do you see in this image?",
"https://assets.puter.site/doge.jpeg"
).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 4: Use Different Models
Specify OpenAI models using the model
parameter:
// Using gpt-4.1
puter.ai.chat("Write a short poem", { model: "gpt-4.1" }).then(response => puter.print(response));
// Using o3-mini
puter.ai.chat("Write a short poem", { model: "o3-mini" }).then(response => puter.print(response));
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Write a short poem", { model: "gpt-4.1" }).then(response => puter.print(response));
puter.ai.chat("Write a short poem", { model: "o3-mini" }).then(response => puter.print(response));
</script>
</body>
</html>
Example 5: Stream Responses
Stream responses for long output:
async function streamResponse() {
const response = await puter.ai.chat(
"Explain the theory of relativity in detail",
{ stream: true }
);
for await (const part of response) {
puter.print(part?.text);
}
}
streamResponse();
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
async function streamResponse() {
const response = await puter.ai.chat(
"Explain the theory of relativity in detail",
{ stream: true }
);
for await (const part of response) {
puter.print(part?.text);
}
}
streamResponse();
</script>
</body>
</html>
Supported OpenAI Models
The following OpenAI models are supported by Puter.js
:
gpt-4.1
gpt-4.1-mini
gpt-4.1-nano
gpt-4.5-preview
gpt-4o
gpt-4o-mini
o1
o1-mini
o1-pro
o3
o3-mini
o4-mini
That's It!
You now have a free alternative to the OpenAI API using Puter.js.
This allows you to access GPT-4o
, o4
, o3-mini
,
o1-mini
, DALL·E
, and more — all without needing an API key
or a backend. True serverless AI!