Free, Unlimited Gemini API
On this page
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 4 Hydrogen, Gemini 4 Carbon, Gemini 4 Argon, and Gemini 3.5 Flash-Lite 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.
Puter.js is also an exceptional fit for AI coding assistants, agents, and vibe coding platforms like Claude Code, Codex, OpenCode, Lovable, Replit, Bolt.new, and the rest. Because there are no keys and no backend involved, anything these tools produce, with Puter.js, runs end-to-end as soon as it's generated. No third-party signup, no service to spin up, no API keys to paste. That cuts out a whole category of security pitfalls and the configuration overhead that normally stops AI-generated apps from working on the first run.
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 Gemini capabilities. No API keys or sign-ups 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 black holes in simple terms", {
model: 'gemini-4-hydrogen'
}).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 2: Using Gemini 4 Argon
For harder, multi-step tasks, use Gemini 4 Argon, Google's flagship Gemini 4 model:
<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: 'gemini-4-argon'
}).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 3: Code Security Review with Gemini 4 Carbon
Gemini 4 Carbon is the top model in Google's Gemini 4 family, built for long software engineering tasks and defensive security work such as 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: 'gemini-4-carbon'
}).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 4: Cost-Efficient Generation with Gemini 3.5 Flash-Lite
Gemini 3.5 Flash-Lite is Google's fastest and most cost-efficient model in the Gemini 3.5 series, suited for high-volume tasks like translation, classification, and content moderation:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Classify the following text as positive, negative, or neutral: 'The product works well but the delivery was late.'", {
model: 'gemini-3.5-flash-lite'
}).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 5: 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');
// Gemini 4 Hydrogen with streaming
outputDiv.innerHTML += '<h2>Gemini 4 Hydrogen Response:</h2>';
const hydrogenResponse = await puter.ai.chat(
"Explain the process of photosynthesis in detail",
{
model: 'gemini-4-hydrogen',
stream: true
}
);
for await (const part of hydrogenResponse) {
if (part?.text) {
outputDiv.innerHTML += part.text.replaceAll('\n', '<br>');
}
}
}
streamResponses();
</script>
</body>
</html>
Example 6: Comparing Models
Here's how to compare responses from multiple Gemini models:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// Gemini 4 Hydrogen
const hydrogen_resp = await puter.ai.chat(
'Tell me something interesting about quantum mechanics.',
{model: 'gemini-4-hydrogen', stream: true}
);
puter.print('<h2>Gemini 4 Hydrogen Response:</h2>');
for await (const part of hydrogen_resp) {
if (part?.text) {
puter.print(part.text.replaceAll('\n', '<br>'));
}
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// Gemini 4 Hydrogen
const hydrogen_resp = await puter.ai.chat(
'Tell me something interesting about quantum mechanics.',
{model: 'gemini-4-hydrogen', stream: true}
);
puter.print('<h2>Gemini 4 Hydrogen Response:</h2>');
for await (const part of hydrogen_resp) {
if (part?.text) {
puter.print(part.text.replaceAll('\n', '<br>'));
}<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// Gemini 4 Hydrogen
const hydrogen_resp = await puter.ai.chat(
'Tell me something interesting about quantum mechanics.',
{model: 'gemini-4-hydrogen', stream: true}
);
puter.print('<h2>Gemini 4 Hydrogen Response:</h2>');
for await (const part of hydrogen_resp) {
if (part?.text) {
puter.print(part.text.replaceAll('\n', '<br>'));
}
}
// Gemini 4 Argon
const argon_resp = await puter.ai.chat(
'Tell me something interesting about quantum mechanics.',
{model: 'gemini-4-argon', stream: true}
);
puter.print('<h2>Gemini 4 Argon Response:</h2>');
for await (const part of argon_resp) {
if (part?.text) {
puter.print(part.text.replaceAll('\n', '<br>'));
}
}
// Gemini 3.5 Flash-Lite
const flashlite35_resp = await puter.ai.chat(
'Tell me something interesting about quantum mechanics.',
{model: 'gemini-3.5-flash-lite', stream: true}
);
puter.print('<h2>Gemini 3.5 Flash-Lite Response:</h2>');
for await (const part of flashlite35_resp) {
if (part?.text) {
puter.print(part.text.replaceAll('\n', '<br>'));
}
}
})();
</script>
</body>
</html>
Example 7: Image Analysis
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?",
"https://assets.puter.site/doge.jpeg",
{ model: 'gemini-4-hydrogen' }
).then(response => {
puter.print(response);
});
</script>
</body>
</html>
All models
The following Gemini models are available for free use with Puter.js:
gemini-4-hydrogen
gemini-4-carbon
gemini-4-argon
gemini-3.8-flash
gemini-3.7-flash
gemini-3.6-flash
gemini-3.5-flash-lite
gemini-3.5-flash
gemini-3.1-flash-lite
gemini-3.1-pro-preview
gemini-3-flash-preview
gemini-3-pro-preview
gemini-2.5-flash-preview-09-2025
gemini-2.5-flash-lite
gemini-2.5-pro-preview
gemini-2.5-pro-preview-05-06
gemini-2.5-flash
gemini-2.5-pro
Puter.js support for Gemini is not limited to text generation, you can also use it for image generation via Gemini 2.5 Flash/3 Pro Image, also known as Nano Banana! Please refer to the Gemini Image Generation tutorial for more information.
Text-to-Speech with Gemini
Puter.js also supports Gemini TTS, giving you access to Google's text-to-speech models with 30 unique voices and natural language style control. Available models include gemini-2.5-flash-preview-tts, gemini-2.5-pro-preview-tts, and gemini-3.1-flash-tts-preview.
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.txt2speech("Hello! This is Gemini text-to-speech.", {
provider: "gemini",
model: "gemini-2.5-flash-preview-tts",
voice: "Puck",
instructions: "Speak in a friendly, upbeat tone."
}).then(audio => {
audio.play();
});
</script>
</body>
</html>
You can use the instructions parameter to control the speaking style with plain English. For a full list of available voices, see the Text-to-Speech API Documentation.
Gemini Free API Key
Unlike most providers, Google does offer a real free tier on the Gemini API, where the Flash-family models are free within rate limits and no credit card is required. The catches are that your prompts get used to improve Google's products, the Pro models are paid-only, and you have rate limits to design around. With Puter.js, you don't have to deal with any of that. There's no API key to manage, no rate limits, the Pro models are included, and each user covers their own usage through their Puter account.
Conclusion
That's it! You now have free access to Gemini's powerful capabilities using Puter.js, from text generation and image analysis to text-to-speech. This allows you to add sophisticated AI features to your web applications without worrying about API keys or usage limits.
Related
- Free, Unlimited Nano Banana (Gemini 3 Pro and 2.5 Flash Image) API
- Free, Unlimited Google AI API
- Free, Unlimited Gemma API
- Free, Unlimited OpenAI API
- Free, Unlimited Claude API
- Free, Unlimited OpenRouter API
- Free, Unlimited Grok API
- Free, Unlimited Mistral API
- Free, Unlimited Llama API
- Free, Unlimited Amazon Nova API
- Free, Unlimited DeepSeek API
- Free, Unlimited Liquid AI API
- Free, Unlimited Kimi API
- Free, Unlimited Inception Mercury API
- Gemini API Pricing
Ship a Full-Stack App with One Prompt
Build an AI chat app using Puter.js
Coding manually? see the guide