Grok by xAI
Grok is a family of Large Language Models (LLMs) developed by xAI.
Inspired by the Hitchhiker's Guide to the Galaxy, Grok is a maximally truth-seeking AI that provides insightful, unfiltered truths about the universe.
xAI offers an API for developers to interact with our Grok models.
The xAI API is a toolkit for developers to integrate xAI's Grok models into their own applications, the xAI API provides the building blocks to create new AI experiences.
Check out our models that include grok-4 with deep domain knowledge, and grok-4-fast a lightweight model that thinks before responding.
Start by connecting to your existing project and then run vercel link in the CLI to link to the project locally.
Run vercel env pull to make the latest environment variables available to your project locally.
Run npm install @ai-sdk/xai ai openai dotenv to install
@ai-sdk/xai and ai)dotenv for loading the .env.local file created by vercel env pullimport dotenv from "dotenv";import { xai } from "@ai-sdk/xai";import { streamText } from "ai";
dotenv.config({ path: ".env.local" });
const result = streamText({ model: xai("grok-4"), prompt: "Invent a new holiday and describe its traditions.",});
for await (const textPart of result.textStream) { process.stdout.write(textPart);}Start by connecting to your existing project and then run vercel link in the CLI to link to the project locally.
Run vercel env pull to make the latest environment variables available to your project locally.
Run npm install openai dotenv to install
dotenv for loading the .env.local file created by vercel env pull.import dotenv from "dotenv";import OpenAI from "openai";
dotenv.config({ path: ".env.local" });
// Create SDK client using your API keyconst client = new OpenAI({ apiKey: process.env.XAI_API_KEY, baseURL: "https://api.x.ai/v1",});
// Our API is fully compatible with the OpenAI SDKs, so make a request like soconst completion = await client.chat.completions.create({ model: "grok-4", messages: [ { role: "system", content: "You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.", }, { role: "user", content: "What is the meaning of life, the universe, and everything?", }, ],});
console.log(completion.choices[0].message.content);On installing the xAI integration you will be provided the option to add Grok and purchase credits.
Once installed, you can start using Grok immediately with an API key that is automatically provisioned for you.
Your product will provide you access to an API key via anXAI_API_KEY environment variable.
Clicking "Open in Grok" allows you to explore the available models in the xAI console. You can also experiment with them in the playground before integrating them into your application. Our API supports OpenAI, and Anthropic compatible endpoints, making it easy to get started without writing custom code.
Check out the tutorial in our docs for more information.