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-5.4, GPT-5.3 Chat, GPT-5.2, GPT-5.3-Codex, GPT Image, 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.
Getting Started
To use Puter.js, import our NPM library 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:
puter.ai.txt2img("A futuristic cityscape at night", { model: "gpt-image-1.5" })
.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-1.5" })
.then(imageElement => {
document.body.appendChild(imageElement);
});
</script>
</body>
</html>
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-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 do you see in this image?",
"https://assets.puter.site/doge.jpeg",
{ model: "gpt-5.4-nano" }
)
.then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 4: Use different OpenAI models
You can specify different OpenAI models using the model parameter:
// Using gpt-5.4 model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-5.4" }
).then(response => {
puter.print(response);
});
// Using gpt-5.3-chat model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-5.3-chat" }
).then(response => {
puter.print(response);
});
// Using gpt-5.2 model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-5.2" }
).then(response => {
puter.print(response);
});
Full code example:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Using gpt-5.4 model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-5.4" }
).then(response => {
puter.print(response);
});
// Using gpt-5.3-chat model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-5.3-chat" }
).then(response => {
puter.print(response);
});
// Using gpt-5.2 model
puter.ai.chat(
"Write a short poem about coding",
{ model: "gpt-5.2" }
).then(response => {
puter.print(response);
});
</script>
</body>
</html>
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-5.2-chat",
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-5.2-chat",
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-5.4-mini
gpt-5.4-nano
gpt-5.4
gpt-5.4-pro
gpt-5.3-chat
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.4-mini
gpt-5.4-nano
gpt-5.4
gpt-5.4-pro
gpt-5.3-chat
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-maxgpt-5.4-mini
gpt-5.4-nano
gpt-5.4
gpt-5.4-pro
gpt-5.3-chat
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-codex
gpt-5
gpt-5-mini
gpt-5-nano
gpt-5-chat-latest
gpt-4.1
gpt-4.1-mini
gpt-4.1-nano
gpt-4.5-preview
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-1.5
gpt-image-1-mini
gpt-image-1
dall-e-3
dall-e-2
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
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
- 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
- How to Get an OpenAI API Key
Free, Serverless AI and Cloud
Start creating powerful web applications with Puter.js in seconds!
Get Started Now