Free, Unlimited Baidu AI API
On this page
This tutorial will show you how to use Puter.js to access Baidu AI APIs and capabilities—including ERNIE 4.5, Qianfan OCR, and CoBuddy—for chat, reasoning, vision, and more, 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>
Example 4: Basic OCR
Here's a simple example that extracts text from an image using Qianfan OCR Fast:
<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/letter.png",
{ model: 'baidu/qianfan-ocr-fast:free' }
).then(response => {
document.write(response);
});
</script>
</body>
</html>
Example 5: Code Generation
For coding tasks, use Qianfan Cobuddy, a code generation model optimized for coding and agent workflows:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat(
"Write a Python function that checks if a string is a palindrome.",
{ model: "baidu/cobuddy:free" }
).then(response => {
puter.print(response, {code: true});
});
</script>
</body>
</html>
List of supported models
The following Baidu models are supported by Puter.js:
baidu/qianfan-ocr-fast:free
baidu/cobuddy:free
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, Unlimited Essential AI API
- Free, Unlimited Inception Mercury API
- Free, Unlimited Nous Research Hermes API
- Free, Unlimited ArceeAI API
- Free, Unlimited Z.AI GLM API
- Free, Unlimited Tencent Hunyuan API
- Free, Unlimited AllenAI API
- Free, Unlimited StepFun AI API
- Free, Unlimited AI21 Labs API
- Free, Unlimited Inflection AI API
Free, Serverless AI and Cloud
Start creating powerful web applications with Puter.js in seconds!
Get Started Now