Free, Unlimited Microsoft Phi API
On this page
This tutorial will show you how to use Puter.js to access Microsoft's powerful Phi AI models for free. Using Puter.js, you can leverage models like Phi 4 without any API keys or usage restrictions.
Puter is the pioneer of the "User-Pays" model, which allows developers to add AI capabilities to their applications while users cover their own usage costs. This model enables developers to access advanced AI features for free, 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>
You're now ready to use Puter.js to Microsoft Phi capabilities. No API keys or sign-ups are required.
Example 1: Basic Chat
Here's a simple example showing how to generate text using Microsoft Phi 4:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Explain the concept of machine learning in simple terms", {
model: 'microsoft/phi-4'
}).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Using the puter.ai.chat() function, you can generate text using Microsoft Phi 4, which provides excellent performance for general conversational tasks and reasoning.
Example 2: Lightweight Inference with Phi 4 Mini Instruct
Phi 4 Mini Instruct is a 3.8B parameter small language model. Its compact size means lower latency and reduced compute requirements, making it a good fit for high-throughput tasks and on-the-fly responses:
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Summarize the key differences between supervised and unsupervised learning", {
model: 'microsoft/phi-4-mini-instruct'
}).then(response => {
puter.print(response);
});
</script>
</body>
</html>
Example 3: Streaming Response
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 streamResponse() {
const outputDiv = document.getElementById('output');
const response = await puter.ai.chat(
"Explain the theory of relativity and its implications for space travel",
{
model: 'microsoft/phi-4',
stream: true
}
);
for await (const part of response) {
if (part?.text) {
outputDiv.innerHTML += part.text.replaceAll('\n', '<br>');
}
}
}
streamResponse();
</script>
</body>
</html>
List of Supported Microsoft Models
The following Microsoft models are supported by Puter.js:
microsoft/phi-4-mini-instruct
microsoft/phi-4
microsoft/wizardlm-2-8x22b
That's it! You now have free access to Microsoft's powerful Phi model 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