Free, Unlimited Baidu ERNIE API
On this page
This tutorial will show you how to use Puter.js to access Baidu's ERNIE 4.5 family of models—from general chat to reasoning and vision, without any API keys or usage restrictions.
Puter.js uses the User-Pays model, where users of your application cover their own AI costs. This means you as a developer don't pay anything for your users' usage, making your app practically free to run. This model enables developers to add AI capabilities to their app for free, without any API keys or server-side setup.
Getting Started
To use Puter.js, import our NPM library in your project:
// npm install @heyputer/puter.js
import { puter } from '@heyputer/puter.js';
Or alternatively, add our script via CDN if you are working directly with HTML, simply add it to the <head> or <body> section of your code:
<script src="https://js.puter.com/v2/"></script>
Nothing else is required to start using Puter.js for free access to Baidu ERNIE models and capabilities.
Example 1: Basic Chat with ERNIE 4.5
To generate text using ERNIE 4.5 21B A3B, use the puter.ai.chat() function:
puter.ai.chat("Tell me a fun trivia fact about space.", { model: "baidu/ernie-4.5-21b-a3b" })
.then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Tell me a fun trivia fact about space.", { model: "baidu/ernie-4.5-21b-a3b" })
.then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 2: Complex Reasoning
For complex reasoning, use ERNIE 4.5 21B A3B Thinking with streaming to get results in real-time:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
async function streamResponse() {
const response = await puter.ai.chat(
"Explain quantum computing in detail",
{ model: "baidu/ernie-4.5-21b-a3b-thinking", stream: true }
);
for await (const part of response) {
if (part?.reasoning) puter.print(part?.reasoning);
else puter.print(part?.text);
}
}
streamResponse();
</script>
</body>
</html>
Example 3: Image Analysis
To analyze images, simply provide an image URL to puter.ai.chat():
<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",
{ model: 'baidu/ernie-4.5-vl-28b-a3b' }
).then(response => {
document.write(response);
});
</script>
</body>
</html>
List of supported models
The following Baidu ERNIE models are supported by Puter.js:
baidu/ernie-4.5-21b-a3b
baidu/ernie-4.5-21b-a3b-thinking
baidu/ernie-4.5-300b-a47b
baidu/ernie-4.5-vl-28b-a3b
baidu/ernie-4.5-vl-424b-a47b
Conclusion
Using Puter.js, you can access Baidu ERNIE model capabilities without needing an API key or a backend. And thanks to the User-Pays model, your users cover their own AI usage, not you as the developer. This means you can build powerful applications without worrying about AI usage costs.
You can find all AI features supported by Puter.js in the documentation.
Related Resources
Free, Serverless AI and Cloud
Start creating powerful web applications with Puter.js in seconds!
Get Started Now