Tutorials

Free, Unlimited Inception Mercury API

This tutorial will show you how to use Puter.js to access Inception Mercury, the first diffusion large language model (dLLM) that enables fast response times, completely free, without any API keys or usage restrictions.

Puter is the pioneer of the "User-Pays" model, which allows developers to incorporate AI capabilities into their applications with each user covering their own usage costs. This model enables developers to access advanced AI capabilities for free, without any API keys or server-side setup.

Getting Started

You can use Puter.js 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>

Nothing else is required to start using Puter.js for free access to Inception Mercury and its blazing-fast AI capabilities.

Example 1: Basic conversational AI with Mercury

To generate text using Inception Mercury, use the puter.ai.chat() function:

puter.ai.chat("Explain the concept of machine learning in simple terms", { model: "inception/mercury" })
.then(response => {
    puter.print(response);
});

Full code example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("Explain the concept of machine learning in simple terms", { model: "inception/mercury" })
            .then(response => {
                puter.print(response);
            });
    </script>
</body>
</html>

Example 2: Generate code with Mercury-Coder

Mercury-Coder is optimized for code generation tasks. Here's how to use it for writing code:

puter.ai.chat(
    "Write a JavaScript function that sorts an array of objects by a specific property",
    { model: "inception/mercury-coder" }
)
.then(response => {
    puter.print(response, {code: true});
});

Full code example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "Write a JavaScript function that sorts an array of objects by a specific property",
            { model: "inception/mercury-coder" }
        )
        .then(response => {
            puter.print(response, {code: true});
        });
    </script>
</body>
</html>

Example 3: Fast problem-solving with Mercury

Mercury's diffusion-based architecture makes it ideal for quick problem-solving and analysis:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "What are the key advantages of using a microservices architecture?",
            { model: "inception/mercury" }
        )
        .then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

Example 4: 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 evolution of programming languages from assembly to modern high-level languages",
        { model: "inception/mercury", stream: true }
    );

    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 evolution of programming languages from assembly to modern high-level languages",
                { model: "inception/mercury", stream: true }
            );

            for await (const part of response) {
                puter.print(part?.text);
            }
        }

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

Example 5: Complex code generation with streaming

Combine Mercury-Coder's capabilities with streaming for complex code generation tasks:

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

            const response = await puter.ai.chat(
                "Create a React component with hooks for managing a todo list with add, delete, and toggle functionality",
                { model: "inception/mercury-coder", stream: true }
            );

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

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

List of supported models

The following Inception Mercury models are supported by Puter.js:

inception/mercury
inception/mercury-coder



That's it! You now have a free access to the Inception Mercury API using Puter.js. This allows you to access the first diffusion large language model for blazing-fast AI responses without needing an API key or a backend. True serverless AI!

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