Ship a Full-Stack App with One Prompt

Copy this prompt into your AI coding agent, or open it in one below.

Give this to your AI Create a to-do list app using Puter.js

Coding manually? see the guide

Tutorials

Free, Unlimited Google AI API

On this page

This tutorial will show you how to use Puter.js to access Google AI's powerful language models for free, without any API keys or usage restrictions. Using Puter.js, you can leverage models like Gemini 4 Hydrogen, Gemini 4 Carbon, Gemini 4 Argon, Gemini 3.5 Flash-Lite, and the Gemma 4 series for various tasks including text generation, image analysis, complex reasoning, and more.

Puter is the inventor of the "User-Pays" model, which lets developers add AI features to their apps while end users handle their own usage costs. This approach allows developers to tap into advanced AI tools for free, with no need for API keys, backend setup, or server-side code.

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>

You're now ready to use Puter.js for free access to Google AI capabilities. No API keys or server-side setup are required.

Example 1: Basic Text Generation with Gemini 4 Hydrogen

Here's a simple example showing how to generate text using Gemini 4 Hydrogen, Google's everyday model in the Gemini 4 family:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("Explain the concept of machine learning in simple terms", {
            model: 'google/gemini-4-hydrogen'
        }).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

Example 2: Using Gemini 4 Argon for Complex Reasoning

For more sophisticated tasks requiring deeper analysis, use Gemini 4 Argon, Google's flagship Gemini 4 model:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "Compare and contrast the economic impacts of renewable versus non-renewable energy sources over the next 20 years", 
            {
                model: 'google/gemini-4-argon'
            }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

Example 3: Code Security Review with Gemini 4 Carbon

For software engineering and security work, use Gemini 4 Carbon, the top model in Google's Gemini 4 family. It is built for long coding tasks and for finding and patching vulnerabilities:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        const code = `
function getUser(db, userId) {
    return db.query("SELECT * FROM users WHERE id = " + userId);
}`;

        puter.ai.chat(
            "Find the security vulnerability in this code and show a patched version:\n" + code,
            {
                model: 'google/gemini-4-carbon'
            }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

Example 4: Streaming Responses

For longer responses, use streaming to get results in real-time:

<html>
<body>
    <div id="output"></div>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        async function streamResponses() {
            const outputDiv = document.getElementById('output');
            
            outputDiv.innerHTML += '<h2>Gemini 4 Hydrogen Streaming Response:</h2>';
            const response = await puter.ai.chat(
                "Explain the process of photosynthesis in detail", 
                {
                    model: 'google/gemini-4-hydrogen',
                    stream: true
                }
            );
            
            for await (const part of response) {
                if (part?.text) {
                    outputDiv.innerHTML += part.text.replaceAll('\n', '<br>');
                }
            }            
        }

        streamResponses();
    </script>
</body>
</html>

Example 5: Image Analysis with Gemini

To analyze images, simply provide an image URL to puter.ai.chat():

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <img src="https://assets.puter.site/doge.jpeg" id="image">
    <script>
        puter.ai.chat(
            "What do you see in this image? Describe it in detail.",
            "https://assets.puter.site/doge.jpeg",
            { model: 'google/gemini-4-hydrogen' }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

Example 6: Comparing Different Google AI Models

Here's how to compare responses from different Google AI models:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
    (async () => {
        const prompt = 'Explain quantum entanglement in simple terms.';
        
        // Gemini 4 Argon
        const argonResp = await puter.ai.chat(
            prompt,
            {model: 'google/gemini-4-argon', stream: true}
        );
        puter.print('<h2>Gemini 4 Argon Response:</h2>');
        for await (const part of argonResp) {
            if(part?.reasoning) {
Show 34 more lines...
<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
    (async () => {
        const prompt = 'Explain quantum entanglement in simple terms.';
        
        // Gemini 4 Argon
        const argonResp = await puter.ai.chat(
            prompt,
            {model: 'google/gemini-4-argon', stream: true}
        );
        puter.print('<h2>Gemini 4 Argon Response:</h2>');
        for await (const part of argonResp) {
            if(part?.reasoning) {
                puter.print(part.reasoning.replaceAll('\n', '<br>'));
            }
            if (part?.text) {
                puter.print(part.text.replaceAll('\n', '<br>'));
            }
        }

        // Gemini 4 Hydrogen
        const hydrogenResp = await puter.ai.chat(
            prompt,
            {model: 'google/gemini-4-hydrogen', stream: true}
        );
        puter.print('<h2>Gemini 4 Hydrogen Response:</h2>');
        for await (const part of hydrogenResp) {
            if (part?.text) {
                puter.print(part.text.replaceAll('\n', '<br>'));
            }
        }

        // Gemini 3.5 Flash-Lite
        const flashLiteResp = await puter.ai.chat(
            prompt,
            {model: 'google/gemini-3.5-flash-lite', stream: true}
        );
        puter.print('<h2>Gemini 3.5 Flash-Lite Response:</h2>');
        for await (const part of flashLiteResp) {
            if (part?.text) {
                puter.print(part.text.replaceAll('\n', '<br>'));
            }
        }
    })();
    </script>
</body>
</html>
Collapse code

Example 7: Using Gemma Models for Lightweight Tasks

The Gemma series offers efficient, open-weight models perfect for high-throughput tasks:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        // Using Gemma 4 31B model
        puter.ai.chat(
            "Write a haiku about coding",
            { model: 'google/gemma-4-31b-it' }
        ).then(response => {
            puter.print('<h2>Gemma 4 31B Response:</h2>');
            puter.print(response);
        });
    </script>
</body>
</html>

Example 8: Control Output with Temperature

Control the creativity and randomness of responses using the temperature parameter:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        (async () => {
            // Low temperature (0.2) for focused, deterministic output
            const focused = await puter.ai.chat(
                'Write a creative story about a robot', 
                { 
                    model: 'google/gemini-3.8-flash',
                    temperature: 0.2
                }
            );
            puter.print('<b>Low temperature (0.2) - More Focused:</b><br>' + focused + '<br><br>');
            
            // High temperature (0.9) for creative, varied output  
            const creative = await puter.ai.chat(
                'Write a creative story about a robot',
                { 
                    model: 'google/gemini-3.8-flash',
                    temperature: 0.9
                }
            );
            puter.print('<b>High temperature (0.9) - More Creative:</b><br>' + creative);
        })();
    </script>
</body>
</html>

All Available Google AI Models

The following Google AI models are available for free use with Puter.js:

Gemini Models

google/gemini-4-hydrogen
google/gemini-4-carbon
google/gemini-4-argon
google/gemini-3.8-flash
google/gemini-3.7-flash
google/gemini-3.6-flash
google/gemini-3.5-flash
google/gemini-3.5-flash-lite
google/gemini-3.1-pro-preview
google/gemini-3.1-flash-lite
google/gemini-3-pro-preview
google/gemini-3-flash-preview
google/gemini-2.5-pro
google/gemini-2.5-pro-preview
google/gemini-2.5-pro-preview-05-06
google/gemini-2.5-flash
google/gemini-2.5-flash-preview-09-2025
google/gemini-2.5-flash-lite

Gemma Models

google/gemma-4-31b-it
google/gemma-4-26b-a4b-it
google/gemma-3-27b-it
google/gemma-3-12b-it
google/gemma-3-4b-it
google/gemma-2-27b-it

That's it! You now have free access to Google AI's powerful language models using Puter.js. This allows you to add sophisticated AI capabilities to your web applications without worrying about API keys, usage limits, or backend infrastructure.

Ship a Full-Stack App with One Prompt

Give this to your AI Build an AI chat app using Puter.js

Coding manually? see the guide