Tutorials

Free, Unlimited Gemini API

This tutorial will show you how to use Puter.js to access Gemini's powerful language models for free, without any API keys or usage restrictions. Using Puter.js, you can leverage models like Gemini 2.0 Flash, Gemini 2.5 Pro, and Gemini 1.5 Flash for various tasks like text generation, image analysis, and complex reasoning, text and code generation, and more.

Puter is the pioneer of the "User Pays" model, which allows developers to incorporate AI capabilities into their applications while users 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

Puter.js works 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>

You're now ready to use Puter.js for free access to Gemini capabilities. No API keys or sign-ups are required.

Example 1Basic Text Generation with Gemini 2.0 Flash

Here's a simple example showing how to generate text using Gemini 2.0 Flash:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("Explain the concept of black holes in simple terms", {
            model: 'google/gemini-2.0-flash-lite-001'
        }).then(response => {
            document.write(response.message.content);
        });
    </script>
</body>
</html>

Example 2Using Gemini 2.5 Pro

For comparison, here's how to use Gemini 2.5 Pro:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "What are the major differences between renewable and non-renewable energy sources?", 
            {
                model: 'google/gemini-2.5-pro-exp-03-25:free'
            }
        ).then(response => {
            document.write(response.message.content);
        });
    </script>
</body>
</html>

Example 3Streaming 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');
            
            // Gemini 2.0 Flash with streaming
            outputDiv.innerHTML += '<h2>Gemini 2.0 Flash Response:</h2>';
            const flash2Response = await puter.ai.chat(
                "Explain the process of photosynthesis in detail", 
                {
                    model: 'gemini-2.0-flash',
                    stream: true
                }
            );
            
            for await (const part of flash2Response) {
                if (part?.text) {
                    outputDiv.innerHTML += part.text.replaceAll('\n', '<br>');
                }
            }            
        }

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

Example 4Comparing Models

Here's how to compare responses from both Gemini models:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
    (async () => {
        // Gemini 2.5 Pro
        const pro_resp = await puter.ai.chat(
            'Tell me something interesting about quantum mechanics.',
            {model: 'google/gemini-2.5-pro-exp-03-25:free'}
        );
        document.write('<h2>Gemini 2.5 Pro Response:</h2>');
        document.write(pro_resp.message.content);

        // Gemini 2.0 Flash
        const flash2_resp = await puter.ai.chat(
            'Tell me something interesting about quantum mechanics.',
            {model: 'google/gemini-2.0-flash-lite-001', stream: true}
        );
        document.write('<h2>Gemini 2.0 Flash Response:</h2>');
        for await (const part of flash2_resp) {
            if (part?.text) {
                document.write(part.text.replaceAll('\n', '<br>'));
            }
        }

        // Gemini 1.5 Flash
        const flash1_resp = await puter.ai.chat(
            'Tell me something interesting about quantum mechanics.',
            {model: 'google/gemini-flash-1.5-8b', stream: true}
        );
        document.write('<h2>Gemini 1.5 Flash Response:</h2>');
        for await (const part of flash1_resp) {
            if (part?.text) {
                document.write(part.text.replaceAll('\n', '<br>'));
            }
        }
    })();
    </script>
</body>
</html>

Example 5Image 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: 'google/gemini-2.0-flash-lite-001' }
        ).then(response => {
            document.write(response);
        });
    </script>
</body>
</html>

All models

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

google/gemini-2.0-flash-001
google/gemini-2.0-flash-exp:free
google/gemini-2.0-flash-lite-001
google/gemini-2.5-flash
google/gemini-2.5-flash-image-preview
google/gemini-2.5-flash-image-preview:free
google/gemini-2.5-flash-lite
google/gemini-2.5-flash-lite-preview-06-17
google/gemini-2.5-pro
google/gemini-2.5-pro-exp-03-25
google/gemini-2.5-pro-preview
google/gemini-2.5-pro-preview-05-06
google/gemini-flash-1.5
google/gemini-flash-1.5-8b
google/gemini-pro-1.5
google/gemma-2-27b-it
google/gemma-2-9b-it
google/gemma-2-9b-it:free
google/gemma-3-12b-it
google/gemma-3-12b-it:free
google/gemma-3-27b-it
google/gemma-3-27b-it:free
google/gemma-3-4b-it
google/gemma-3-4b-it:free
google/gemma-3n-e2b-it:free
google/gemma-3n-e4b-it
google/gemma-3n-e4b-it:free

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

Related

Free, Serverless AI and Cloud

Start creating powerful web applications with Puter.js in seconds!

Get Started Now

Read the Docs Try the Playground