Free, Unlimited Amazon Ergo API
On this page
In this tutorial, you will learn how to add Amazon Ergo into your application for free using Puter.js. Ergo 1.0 is Amazon's reasoning model for software engineering and agentic workflows, such as building features, refactoring, migrating code, debugging, and testing.
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. You can scale to unlimited users and pay nothing for the AI or server usage.
Getting Started
To use Puter.js, import our npm module 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 Amazon Ergo.
Example 1: Code Generation with Ergo 1.0
To generate code, use the puter.ai.chat() function with Ergo 1.0:
puter.ai.chat(
"Write a JavaScript function that groups an array of objects by a given key, with unit tests.",
{ model: "amazon/ergo-1.0" }
).then(response => {
puter.print(response, { code: true });
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat(
"Write a JavaScript function that groups an array of objects by a given key, with unit tests.",
{ model: "amazon/ergo-1.0" }
).then(response => {
puter.print(response, { code: true });
});
</script>
</body>
</html>
Example 2: Streaming a Refactoring Task
Ergo uses reasoning on every request, so longer coding tasks can take a while to finish. Use streaming to show the output as it arrives:
<html>
<body>
<pre id="response"></pre>
<script src="https://js.puter.com/v2/"></script>
<script>
async function streamResponse() {
const outputEl = document.getElementById('response');
const code = `
function getUser(id, callback) {
db.query('SELECT * FROM users WHERE id = ?', [id], function (err, rows) {
if (err) { callback(err); return; }
callback(null, rows[0]);
});
}`;
<html>
<body>
<pre id="response"></pre>
<script src="https://js.puter.com/v2/"></script>
<script>
async function streamResponse() {
const outputEl = document.getElementById('response');
const code = `
function getUser(id, callback) {
db.query('SELECT * FROM users WHERE id = ?', [id], function (err, rows) {
if (err) { callback(err); return; }
callback(null, rows[0]);
});
}`;<html>
<body>
<pre id="response"></pre>
<script src="https://js.puter.com/v2/"></script>
<script>
async function streamResponse() {
const outputEl = document.getElementById('response');
const code = `
function getUser(id, callback) {
db.query('SELECT * FROM users WHERE id = ?', [id], function (err, rows) {
if (err) { callback(err); return; }
callback(null, rows[0]);
});
}`;
const response = await puter.ai.chat(
`Refactor this function to use async/await, then explain what changed.\n${code}`,
{ model: 'amazon/ergo-1.0', stream: true }
);
for await (const part of response) {
if (part?.text) {
outputEl.textContent += part.text;
}
}
}
streamResponse();
</script>
</body>
</html>
Example 3: Tool Calling
Ergo can call functions you define in your code, which is how you connect it to an agent loop. Pass a tools array to puter.ai.chat(), and the model returns a structured tool call when it needs one:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Define a tool that runs a project's test suite
const tools = [{
type: "function",
function: {
name: "run_tests",
description: "Run the test suite for a file and return the results",
parameters: {
type: "object",
properties: {
file: { type: "string", description: "Path to the test file, e.g. tests/cart.test.js" }
},
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Define a tool that runs a project's test suite
const tools = [{
type: "function",
function: {
name: "run_tests",
description: "Run the test suite for a file and return the results",
parameters: {
type: "object",
properties: {
file: { type: "string", description: "Path to the test file, e.g. tests/cart.test.js" }
},<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Define a tool that runs a project's test suite
const tools = [{
type: "function",
function: {
name: "run_tests",
description: "Run the test suite for a file and return the results",
parameters: {
type: "object",
properties: {
file: { type: "string", description: "Path to the test file, e.g. tests/cart.test.js" }
},
required: ["file"]
}
}
}];
puter.ai.chat(
"I changed the discount logic in the cart. Check that tests/cart.test.js still passes.",
{ model: "amazon/ergo-1.0", tools }
).then(response => {
if (response.message.tool_calls) {
const call = response.message.tool_calls[0];
const args = JSON.parse(call.function.arguments);
puter.print(`Model requested ${call.function.name} with file: ${args.file}`);
} else {
puter.print(response);
}
});
</script>
</body>
</html>
Your code runs the requested function and sends the result back in a follow-up message, so the model can write its final answer from that data.
Example 4: Multi-Turn Debugging Conversation
To keep context across turns, pass an array of messages instead of a single prompt. This example sets a system prompt, asks Ergo to find a bug, then asks a follow-up question about its answer:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
const messages = [
{ role: "system", content: "You are a code reviewer. Keep answers short and point to the exact line." },
{ role: "user", content: "Why does this print 3 three times?\n\nfor (var i = 0; i < 3; i++) {\n setTimeout(() => console.log(i), 100);\n}" }
];
const first = await puter.ai.chat(messages, { model: "amazon/ergo-1.0" });
puter.print("<h2>Diagnosis</h2>");
puter.print(first);
// Add the reply to the history, then ask a follow-up
messages.push(first.message);
messages.push({ role: "user", content: "Show the fix without changing var to let." });
const second = await puter.ai.chat(messages, { model: "amazon/ergo-1.0" });
puter.print("<h2>Fix</h2>");
puter.print(second);
})();
</script>
</body>
</html>
Available Models
The following Amazon Ergo model is supported by Puter.js:
amazon/ergo-1.0
Amazon's Nova models use the same puter.ai.chat() function. See the Amazon Nova tutorial for those model IDs.
Conclusion
You now have free access to Amazon Ergo using Puter.js. This allows you to use Ergo 1.0 for code generation, refactoring, tool calling, and multi-turn conversations without needing API keys, an AWS account, or backend infrastructure.
Related
Ship a Full-Stack App with One Prompt
Build an AI chat app using Puter.js
Coding manually? see the guide