Free, Unlimited OpenAI API
On this page
This tutorial will show you how to use Puter.js to access OpenAI API for free, without needing an OpenAI API key. Puter.js allows you to provide your users with powerful AI capabilities. You can access GPT-6.1 Sol, GPT-6.1 Sol Pro, GPT-6 Astra, GPT-6 Astra Pro, GPT-6 Sol, GPT-6 Luna, GPT-5.3-Codex, GPT Image 2.5 Flare, GPT Image 2.5 Sunburst, and more directly from your frontend code without any server-side setup.
Puter is the pioneer of the "User-Pays" model, which allows developers to incorporate AI capabilities into their applications while each user will cover their own usage costs. This model enables developers to offer advanced AI capabilities to users at no cost to themselves, without any API keys or server-side setup.
Puter.js is also uniquely suited for use by AI coding assistants, agents, and vibe coding platforms like Claude Code, Codex, OpenCode, Lovable, Replit, Bolt.new, and more. Because Puter.js is keyless and serverless, AI-generated apps and programs using it work end-to-end without having to sign up for a third-party backend, provision a service, or paste in API keys. This eliminates both a major class of security issues and the setup friction that usually keeps these apps from running out of the box.
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 OpenAI API models and capabilities.
Example 1: Use gpt-5.4-nano for text generation
To generate text using GPT-5.4 Nano, use the puter.ai.chat() function:
puter.ai.chat("What are the benefits of exercise?", { model: "gpt-5.4-nano" })
.then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("What are the benefits of exercise?", { model: "gpt-5.4-nano" })
.then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 2: Generate images with GPT Image
To create images using GPT Image, use the puter.ai.txt2img() function. This example uses GPT Image 2.5 Flare with the model ID gpt-image-2.5-flare:
puter.ai.txt2img("A futuristic cityscape at night", { model: "gpt-image-2.5-flare" })
.then(imageElement => {
document.body.appendChild(imageElement);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.txt2img("A futuristic cityscape at night", { model: "gpt-image-2.5-flare" })
.then(imageElement => {
document.body.appendChild(imageElement);
});
</script>
</body>
</html>
To use GPT Image 2.5 Sunburst, change the model value to "gpt-image-2.5-sunburst" in either example above.
Find more image generation examples in the GPT Image API tutorial.
Example 3: Analyze images
To analyze images, simply provide an image URL to puter.ai.chat():
puter.ai.chat(
"What do you see in this image?",
"https://assets.puter.site/doge.jpeg",
{ model: "gpt-6-luna" }
)
.then(response => {
puter.print(response);
});
Full code example:
<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: "gpt-6-luna" }
)
.then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 4: Use different OpenAI models
You can specify different OpenAI models using the model parameter. In the GPT-6 family, the number marks the generation, while the name marks the capability tier. GPT-6 Astra is the flagship, aimed at complex reasoning, coding, and computer use. GPT-6.1 Sol is the mid-tier, built for development work you run repeatedly, such as building features, reviewing code, and debugging. It is an update to GPT-6 Sol at the same price, and GPT-6 Sol is still available under gpt-6-sol. GPT-6 Luna is the smallest and cheapest, meant for high-volume tasks like summarization and extraction.
// Using gpt-6-astra, the flagship model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-6-astra" }
).then(response => {
puter.print(response);
});
// Using gpt-6.1-sol, the mid-tier model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-6.1-sol" }
).then(response => {
puter.print(response);
});
// Using gpt-6-luna, the smallest and cheapest model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-6-luna" }
).then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Using gpt-6-astra, the flagship model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-6-astra" }
).then(response => {
puter.print(response);
});
// Using gpt-6.1-sol, the mid-tier model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-6.1-sol" }
).then(response => {
puter.print(response);
});
// Using gpt-6-luna, the smallest and cheapest model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-6-luna" }
).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Each GPT-6 tier also has a pro variant (GPT-6 Astra Pro, GPT-6 Sol Pro, and GPT-6 Luna Pro, with the IDs gpt-6-astra-pro, gpt-6-sol-pro, and gpt-6-luna-pro) that runs the same underlying model with reasoning effort set to pro for higher-quality responses on harder problems. Each pro variant shares the 1,050,000-token context window, 128,000 max output tokens, and per-token pricing of its base model. This differs from GPT-5.4 Pro and GPT-5.5 Pro, which cost several times more than their base models. GPT-6.1 Sol Pro (gpt-6.1-sol-pro) is priced the same as GPT-6.1 Sol, though OpenAI's 6.1 documentation does not confirm that it is the same model with a pro reasoning setting. OpenAI has not documented what separates a pro variant from its base model beyond the reasoning setting, so if you are choosing between them, test both on your own prompts rather than assuming Pro is better.
On price, Astra is the most expensive OpenAI model on this list, at five times the per-token cost of GPT-6.1 Sol, so Sol and Luna are the cheaper choice for routine work.
Example 5: Stream responses for longer queries
For longer responses, use streaming to get results in real-time:
async function streamResponse() {
const response = await puter.ai.chat(
"Explain the theory of relativity in detail",
{stream: true, model: "gpt-5.4-nano"}
);
for await (const part of response) {
puter.print(part?.text);
}
}
streamResponse();
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
async function streamResponse() {
const response = await puter.ai.chat(
"Explain the theory of relativity in detail",
{stream: true, model: "gpt-5.4-nano"}
);
for await (const part of response) {
puter.print(part?.text);
}
}
streamResponse();
</script>
</body>
</html>
Example 6: Control randomness and length with `temperature` and `max_tokens`
To control randomness and length, you can use the temperature and max_tokens parameters in the options object:
<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(
'Tell me about planet Mars',
{
temperature: 0.2,
max_tokens: 10
}
);
puter.print('<b>Low temperature (0.2), max_tokens: 10:</b><br>' + focused + '<br><br>');
// High temperature (0.8) for creative, varied output
const creative = await puter.ai.chat(
'Tell me about planet Mars',
{
temperature: 0.8,
max_tokens: 50
}
);
puter.print('<b>High temperature (0.8), max_tokens: 50:</b><br>' + creative);
})();
</script>
</body>
</html>
This example shows how temperature affects output randomness (lower = more focused, higher = more creative) and how max_tokens limits the response length.
Example 7: Tool/Function Calling
Here's a concise section for tool/function calling:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Define a calculator tool
const tools = [{
type: "function",
function: {
name: "calculate",
description: "Perform basic math operations",
parameters: {
type: "object",
properties: {
operation: {
type: "string",
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Define a calculator tool
const tools = [{
type: "function",
function: {
name: "calculate",
description: "Perform basic math operations",
parameters: {
type: "object",
properties: {
operation: {
type: "string",<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Define a calculator tool
const tools = [{
type: "function",
function: {
name: "calculate",
description: "Perform basic math operations",
parameters: {
type: "object",
properties: {
operation: {
type: "string",
enum: ["add", "subtract", "multiply", "divide"]
},
a: { type: "number" },
b: { type: "number" }
},
required: ["operation", "a", "b"]
}
}
}];
// Ask the AI to use the tool
puter.ai.chat("What is 15 multiplied by 7?", { tools }).then(response => {
if (response.message.tool_calls) {
const call = response.message.tool_calls[0];
const args = JSON.parse(call.function.arguments);
// Execute the function based on the AI's request
let result;
if (args.operation === "multiply") {
result = args.a * args.b;
}
puter.print(`AI requested: ${args.a} × ${args.b} = ${result}`);
}
});
</script>
</body>
</html>
This example shows how to define tools that the AI can call and process the function calls in your code.
Example 8: Web Search
Use web search to generate up-to-date and accurate responses from the Internet.
puter.ai
.chat("Summarize what the User-Pays Model is: https://docs.puter.com/user-pays-model/", {
model: "openai/gpt-6-luna",
tools: [{ type: "web_search" }],
})
.then(puter.print);
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.print(`Loading...`);
puter.ai
.chat("Summarize what the User-Pays Model is: https://docs.puter.com/user-pays-model/", {
model: "openai/gpt-6-luna",
tools: [{ type: "web_search" }],
})
.then(puter.print);
</script>
</body>
</html>
Example 9: Basic text-to-speech
OpenAI supports text-to-speech capability which you can use via Puter.js.
puter.ai.txt2speech("Hello world! This is OpenAI text-to-speech.", {
provider: "openai",
})
.then(audio => {
audio.setAttribute("controls", "");
document.body.appendChild(audio);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.print("Loading...");
puter.ai.txt2speech("Hello world! This is OpenAI text-to-speech.", {
provider: "openai",
})
.then(audio => {
audio.setAttribute("controls", "");
document.body.appendChild(audio);
});
</script>
</body>
</html>
Find more text-to-speech examples in the OpenAI Text to Speech API tutorial.
Example 10: Using GPT-OSS model
GPT-OSS is open source model family from OpenAI.
puter.ai
.chat(
"Debug this logic: If I have 3 apples and give away 5, how many do I have?",
{ model: "openai/gpt-oss-120b", stream: true }
)
.then(async (resp) => {
for await (const part of resp) {
if (part?.reasoning) puter.print(part?.reasoning);
else puter.print(part?.text);
}
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai
.chat(
"Debug this logic: If I have 3 apples and give away 5, how many do I have?",
{ model: "openai/gpt-oss-120b", stream: true }
)
.then(async (resp) => {
for await (const part of resp) {
if (part?.reasoning) puter.print(part?.reasoning);
else puter.print(part?.text);
}
});
</script>
</body>
</html>
Find more examples in the GPT OSS API tutorial.
Example 11: Code generation with Codex
Codex is OpenAI's code generation model family, optimized for programming tasks.
puter.ai.chat(
"Write a Python function that implements binary search on a sorted array",
{ model: "openai/gpt-5.3-codex" }
)
.then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat(
"Write a Python function that implements binary search on a sorted array",
{ model: "openai/gpt-5.3-codex" }
)
.then(response => {
puter.print(response);
});
</script>
</body>
</html>
Find more Codex examples in the Codex API tutorial.
List of supported text generation models
The following OpenAI models are supported by Puter.js, which can be used with the puter.ai.chat() function:
gpt-6.1-sol
gpt-6.1-sol-pro
gpt-6-astra
gpt-6-astra-pro
gpt-6-sol
gpt-6-sol-pro
gpt-6-luna
gpt-6-luna-pro
gpt-5.6-sol
gpt-5.6-sol-pro
gpt-5.6-terra
gpt-5.6-terra-pro
gpt-5.6-luna
gpt-5.6-luna-pro
gpt-5.5-pro
gpt-6.1-sol
gpt-6.1-sol-pro
gpt-6-astra
gpt-6-astra-pro
gpt-6-sol
gpt-6-sol-pro
gpt-6-luna
gpt-6-luna-pro
gpt-5.6-sol
gpt-5.6-sol-pro
gpt-5.6-terra
gpt-5.6-terra-pro
gpt-5.6-luna
gpt-5.6-luna-pro
gpt-5.5-progpt-6.1-sol
gpt-6.1-sol-pro
gpt-6-astra
gpt-6-astra-pro
gpt-6-sol
gpt-6-sol-pro
gpt-6-luna
gpt-6-luna-pro
gpt-5.6-sol
gpt-5.6-sol-pro
gpt-5.6-terra
gpt-5.6-terra-pro
gpt-5.6-luna
gpt-5.6-luna-pro
gpt-5.5-pro
gpt-5.5
gpt-5.4-mini
gpt-5.4-nano
gpt-5.4
gpt-5.4-pro
gpt-5.2
gpt-5.2-chat
gpt-5.2-pro
gpt-5.1
gpt-5.1-chat-latest
gpt-5.3-codex
gpt-5.2-codex
gpt-5.1-codex
gpt-5.1-codex-mini
gpt-5.1-codex-max
gpt-5
gpt-5-mini
gpt-5-nano
gpt-5-chat-latest
gpt-4.1
gpt-4.1-mini
gpt-4.1-nano
gpt-4o
gpt-4o-mini
o1
o1-mini
o1-pro
o3
o3-mini
o4-mini
List of supported image generation models
The following GPT Image models are supported by Puter.js, which can be used with the puter.ai.txt2img() function:
gpt-image-2.5-flare
gpt-image-2.5-sunburst
gpt-image-2
gpt-image-1.5
List of supported text-to-speech models
The following OpenAI text-to-speech models are supported by Puter.js, which can be used with the puter.ai.txt2speech() function:
gpt-4o-mini-tts
tts-1
tts-1-hd
OpenAI Free API Key
OpenAI used to give new accounts a small trial credit, but that's been discontinued, so a new API key now starts at zero and you have to add prepaid funds before you can make a single request. Public GitHub repos that promise free API keys don't work either, since those keys get revoked fast and break any app built on them. With Puter.js, you don't have to deal with any of that. There's no API key to manage, no funds to top up, and each user covers their own usage through their Puter account.
Conclusion
Using Puter.js, you can gain access to OpenAI models without having to set up an OpenAI developer account. 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
- How to do OAuth with OpenAI
- Free, Unlimited Codex API
- Free, Unlimited Claude API
- Free, Unlimited OpenRouter API
- Free, Unlimited DeepSeek API
- Free, Unlimited Gemini API
- Free, Unlimited Grok API
- Free, Unlimited Mistral API
- Free, Unlimited Llama API
- Free, Unlimited GPT OSS API
- Free, Unlimited Amazon Nova API
- Free, Unlimited AI API
- Free, Unlimited Nano Banana API
- Free, Unlimited GPT Image API
- Free, Unlimited Text to Speech API
- Free, Unlimited Speech-to-Text API
- Free, Unlimited Translation API
- Free, Unlimited Sentiment Analysis API
- Free, Unlimited Summarization API
- Free, Unlimited Language Detection API
- How to Get an OpenAI API Key
- OpenAI API Pricing
Ship a Full-Stack App with One Prompt
Build an AI chat app using Puter.js
Coding manually? see the guide