Tutorials

Free, Unlimited Cohere API

This tutorial demonstrates how to use Puter.js to access Cohere's advanced language models without any API keys or usage restrictions. Puter.js is completely free and open-source, enabling you to integrate Cohere's powerful AI capabilities into your applications seamlessly. With Puter.js, you can utilize Cohere Command models directly from your frontend code without server-side configuration.

Puter pioneered the "User Pays" model, which empowers developers to incorporate AI capabilities into their applications while users cover their own usage costs. This innovative approach eliminates the need for developers to manage API keys and billing, making advanced AI accessible to everyone.

Getting Started

Puter.js requires no API keys or registration. To begin 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>

That's all you need to start using Puter.js for free access to Cohere models. No API keys or sign-ups required.

Example 1Use Cohere Command for text generation

To generate text using Cohere's Command model, use the puter.ai.chat() function:

puter.ai.chat("Explain the benefits of renewable energy", { model: "cohere/command-r-plus" })
    .then(response => {
        puter.print(response);
    });

Complete example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("Explain the benefits of renewable energy", { model: "cohere/command-r-plus" })
            .then(response => {
                puter.print(response);
            });
    </script>
</body>
</html>

Example 2Different Cohere Models

You can specify various Cohere models using the model parameter:


// Using Command R Plus model
puter.ai.chat(
    "Write a technical summary of machine learning algorithms",
    { model: "cohere/command-r-plus" }
).then(response => {
    puter.print(response);
});

// Using Command R model
puter.ai.chat(
    "Explain quantum computing in simple terms",
    { model: "cohere/command-r" }
).then(response => {
    puter.print(response);
});

// Using Command R Plus 08-2024 model
puter.ai.chat(
    "Create a business plan outline for a sustainable technology startup",
    { model: "cohere/command-r-plus-08-2024" }
).then(response => {
    puter.print(response);
});

Complete example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        // Using Command R Plus model
        puter.ai.chat(
            "Write a technical summary of machine learning algorithms",
            { model: "cohere/command-r-plus" }
        ).then(response => {
            puter.print("<h2>Using Command R Plus model</h2>");
            puter.print(response);
        });

        // Using Command R model
        puter.ai.chat(
            "Explain quantum computing in simple terms",
            { model: "cohere/command-r" }
        ).then(response => {
            puter.print("<h2>Using Command R model</h2>");
            puter.print(response);
        });

        // Using Command R Plus 08-2024 model
        puter.ai.chat(
            "Create a business plan outline for a sustainable technology startup",
            { model: "cohere/command-r-plus-08-2024" }
        ).then(response => {
            puter.print("<h2>Using Command R Plus 08-2024 model</h2>");
            puter.print(response);
        });
    </script>
</body>
</html>

Example 3Streaming for Real-time Responses

For longer outputs, use streaming to display results as they're generated:

async function streamCohere() {
    const response = await puter.ai.chat(
        "Write a detailed analysis of sustainable urban development practices", 
        {
            stream: true,
            model: "cohere/command-r-plus"
        }
    );
    
    for await (const part of response) {
        puter.print(part?.text);
    }
}

streamCohere();

Complete example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        async function streamCohere() {
            const response = await puter.ai.chat(
                "Write a detailed analysis of sustainable urban development practices", 
                {
                    stream: true,
                    model: "cohere/command-r-plus"
                }
            );
            
            for await (const part of response) {
                puter.print(part?.text);
            }
        }

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

Supported Cohere Models

The following Cohere models are available through Puter.js:

cohere/command
cohere/command-a
cohere/command-r
cohere/command-r-03-2024
cohere/command-r-08-2024
cohere/command-r-plus
cohere/command-r-plus-04-2024
cohere/command-r-plus-08-2024
cohere/command-r7b-12-2024

Each model offers different capabilities and performance characteristics, allowing you to choose the best fit for your specific use case.

That's it! You now have free, unlimited access to Cohere's powerful language models using Puter.js. This enables you to leverage Cohere's advanced AI capabilities for tasks like document analysis, multilingual processing, and reasoning without requiring API keys or backend infrastructure. True serverless AI at your fingertips!

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