Tutorials

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

Puter.js works without any API keys. 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 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: 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
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.

Free, Serverless AI and Cloud

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

Get Started Now

Read the Docs Try the Playground