Tutorials

Free, Unlimited Moonshot AI API

This tutorial will show you how to use Puter.js to access Moonshot AI's powerful models including Kimi K2, Kimi K2 Thinking, Kimi Dev 72B, and Kimi Linear capabilities for free, without needing API keys, backend, or server-side setup. Puter.js is completely free for apps, allowing you to provide your users with powerful multilingual AI capabilities without any server-side setup.

Puter pioneered the "User-Pays" model, where developers can integrate AI capabilities into their applications while users cover their own usage costs. This approach lets you offer powerful AI features to your users without worrying about API keys, server setup, or billing.

Getting Started

You can use Puter.js without any API keys or sign-ups. 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>

Nothing else is required to start using Puter.js for free access to Moonshot AI capabilities.

Example 1Chat with Kimi K2

To generate text using Kimi K2, use the puter.ai.chat() function:

puter.ai.chat("Explain artificial intelligence in simple terms", { model: "moonshotai/kimi-k2" })
    .then(response => {
        puter.print(response);
    });

Full code example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("Explain artificial intelligence in simple terms", { model: "moonshotai/kimi-k2" })
            .then(response => {
                puter.print(response);
            });
    </script>
</body>
</html>

Kimi K2 excels at multilingual interactions, particularly with Chinese language processing, making it ideal for applications targeting Chinese-speaking users or requiring multilingual support.

Example 2Complex reasoning with Kimi K2 Thinking

Kimi K2 Thinking is particularly good at agentic reasoning and complex problem-solving:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "What would be the environmental impact of replacing all cars with electric vehicles? Consider both positive and negative effects.",
            { model: 'moonshotai/kimi-k2-thinking' }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

This model provides deep analysis with step-by-step reasoning, making it perfect for complex analytical tasks, strategic planning, and multi-faceted problem solving.

Example 3Coding with Kimi Dev 72B

Kimi Dev 72B is specialized for coding tasks and software development:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "Write a Python function to implement a binary search algorithm with detailed comments explaining each step.",
            { model: 'moonshotai/kimi-dev-72b' }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

This model is optimized for code generation, debugging, code review, and technical documentation, making it an excellent choice for developer-focused applications.

Example 4Streaming responses for better user experience

For longer responses, you can use streaming to get results in real-time:

<html>
<body>
    <div id="response"></div>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        async function streamResponse() {
            const outputDiv = document.getElementById('response');

            const response = await puter.ai.chat(
                "Write a comprehensive guide on building web applications with modern JavaScript frameworks",
                {model: 'moonshotai/kimi-k2', stream: true}
            );

            for await (const part of response) {
                if (part?.text) {
                    outputDiv.innerHTML += part.text;
                }
            }
        }

        streamResponse();
    </script>
</body>
</html>

This example demonstrates streaming responses, which provides a better user experience by showing the AI's response as it's generated rather than waiting for the complete response.

Example 5High performance and cost efficiency with Kimi Linear

Kimi Linear is optimized for high performance and cost efficiency, making it ideal for applications that need fast responses at scale:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "Summarize the key benefits of renewable energy in three concise points.",
            { model: 'moonshotai/kimi-linear-48b-a3b-instruct' }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

This model delivers fast, efficient responses with reduced computational costs, perfect for high-volume applications, customer service bots, content moderation, or any scenario where you need quick, reliable AI responses without sacrificing quality.

List of supported models

The following Moonshot AI models are supported by Puter.js:

moonshotai/kimi-dev-72b
moonshotai/kimi-k2
moonshotai/kimi-k2-thinking
moonshotai/kimi-k2:free
moonshotai/kimi-k2-0905
moonshotai/kimi-linear-48b-a3b-instruct



That's it! You now have free access to Moonshot AI's powerful models using Puter.js. This allows you to build sophisticated multilingual applications with advanced AI features including complex reasoning, coding assistance, and vision capabilities without needing API keys, backend infrastructure, or complex billing management.

Related

Free, Serverless AI and Cloud

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

Get Started Now

Read the Docs Try the Playground