Tutorials
Free, Unlimited OpenAI API
This tutorial will show you how to use Puter.js to access GPT-4o and DALL-E capabilities for free, without needing an OpenAI API key. Puter.js is completely free and open-source, allowing you to provide your users with powerful AI capabilities without any API keys or usage restrictions.
Puter is the pioneer of the "User Pays" model, which allows developers to incorporate AI capabilities into their applications while each user will cover their own usage costs. This model enables developers to access advanced AI capabilities for free, without any API keys or sign-ups.
Getting Started
You can use puter.js without any API keys or sign-ups. To start using Puter.js, include the following script tag in your HTML file, either in the <head>
or <body>
section:
<script src="https://js.puter.com/v2/"></script>
Nothing else is required to start using Puter.js for free access to GPT-4o and DALL-E capabilities.
Example 1Use GPT-4o for text generation
To generate text using GPT-4o, use the puter.ai.chat()
function:
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 2Generate images with DALL-E 3
To create images using DALL-E 3, use 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 3Analyze images with GPT-4o Vision
To analyze images using GPT-4o Vision, provide an image URL to puter.ai.chat()
:
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 4Stream responses for longer queries
For longer responses, use streaming to get results in real-time:
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>
That's it! You now have a free alternative to the OpenAI API using Puter.js. This allows you to access GPT-4o and DALL-E capabilities without needing an API key or managing usage limits.
Related
Ready to Build Your First App?
Start creating powerful web applications with Puter.js today!
Get Started Now