Grok 2 API

Add AI to your application with Puter.js.

Explore Other Models

Model Card

Grok 2 is xAI's frontier language model released in August 2024, featuring advanced capabilities in chat, coding, and reasoning with competitive performance against GPT-4 and Claude 3.5 Sonnet. It integrates real-time information from the X platform and offers improved reasoning over Grok 1.5.

Context Window 131K

tokens

Max Output 131K

tokens

Input Cost $2

per million tokens

Output Cost $10

per million tokens

Release Date Aug 13, 2024

 

API Usage Example

Add AI to your app with just a few lines of code.
No API keys, no backend, no configuration required.

// npm install @heyputer/puter.js
import { puter } from '@heyputer/puter.js';

puter.ai.chat("Explain quantum computing in simple terms").then(response => {
    document.body.innerHTML = response.message.content;
});
<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("Explain quantum computing in simple terms").then(response => {
            document.body.innerHTML = response.message.content;
        });
    </script>
</body>
</html>

View full documentation →

Frequently Asked Questions

What is this Grok 2 API about?

The Grok 2 API gives you access to xAI's chat model through Puter.js. With just a few lines of JavaScript, you can integrate Grok 2 into any web app or Node.js project — no API keys, no backend, and no configuration required.

Who created Grok 2?

Grok 2 was created by xAI and released on Aug 13, 2024.

What is the context window of Grok 2?

Grok 2 supports a context window of 131K tokens. For reference, that is roughly equivalent to 262 pages of text.

What is the max output length of Grok 2?

Grok 2 can generate up to 131K tokens in a single response.

How much does it cost?
The Grok 2 API is available through the User-Pays Model. As a developer, you can add the Grok 2 API to your app for free — your users pay for their own AI costs directly.
Price per 1M tokens
Input$2
Output$10
How do I access the Grok 2 API?

You can access the Grok 2 API with just a few lines of JavaScript — no API keys, no backend, and no configuration required. Include the Puter.js library in your project and start making calls right away. For more details, check out our documentation.

Does the Grok 2 API work with React / Vue / Vanilla JS / Node / etc.?

Yes — the Grok 2 API works with any JavaScript framework, Node.js, or plain HTML through Puter.js. Just include the library and start building. See the documentation for more details.

Get started with Puter.js

Add AI to your application without worrying about API keys or setup.

Explore Models View Tutorials