Skip to content

Grok ​

Chat with Grok, Twitter's built-in AI, and manage your Grok conversations. Grok replies stream back from Twitter as newline-delimited JSON; emusks parses that stream into a single result object for you.

Tip

The high-level grok.ask() is all you need for one-shot questions. Use grok.createConversation() + grok.respond() when you want to manage conversation IDs yourself.

grok.ask(message, opts?) ​

Ask Grok a question. Creates a conversation (unless you pass opts.conversationId), sends the message, and returns the parsed response.

OptionTypeDescription
messagestringYour prompt
opts.conversationIdstringContinue an existing conversation instead of creating a new one
opts.modelstringModel option id (default grok-3-latest, see grok.models())
opts.reasoningbooleanEnable reasoning mode (default false)
opts.deepsearchbooleanEnable DeepSearch (default false)
opts.systemPromptNamestringNamed system prompt
opts.fileAttachmentsarrayAttachment objects to include with the prompt
opts.returnSearchResultsbooleanInclude web search results (default true)
opts.returnCitationsbooleanInclude citations (default true)
opts.rawbooleanReturn the raw NDJSON stream as a string
opts.bodyobjectMerge extra fields into the request body
js
const res = await client.grok.ask("what's the latest on the falcon 9?");
console.log(res.message);
console.log(res.conversationId);

// continue the same conversation
const followUp = await client.grok.ask("and the booster landing?", {
  conversationId: res.conversationId,
});

// reasoning mode
const math = await client.grok.ask("what is 17 * 23? show your reasoning", {
  reasoning: true,
});
console.log(math.reasoning, math.message);

The returned object:

FieldTypeDescription
conversationIdstringThe conversation this response belongs to
messagestringThe assembled final answer
reasoningstringThe assembled reasoning/thinking trace
followUpSuggestionsarraySuggested follow-up prompts
webResultsarrayWeb search results, when search was used
citationsarrayCitations, when returned
imagesarrayGenerated image attachments, when any
agentChatItemIdstringThe response message id (use it to delete)
chunksarrayEvery raw parsed line from the stream

grok.respond(conversationId, message, opts?) ​

Low-level: send a message to an existing conversation. Same opts as ask. Returns the parsed response (without re-wrapping the conversation id).

js
const id = await client.grok.createConversation();
const res = await client.grok.respond(id, "hello");

grok.createConversation() ​

Create an empty Grok conversation on x.com and return its id. Uses the legacy CreateGrokConversation mutation, which still works. The x.com web client now starts conversations on grok.com over a WebSocket, which emusks does not implement.

js
const conversationId = await client.grok.createConversation();

x.com and grok.com ​

Every method here uses the x.com Grok chat by default, the same one ask and respond write to, so conversations you create show up in history. The x.com web client now reads conversations from grok.com /rest/app-chat/* with a JWT from grokAccountJwtQuery. Pass { grokCom: true } to do the same. It falls back to x.com when the account has no linked grok.com account. rename, deleteConversation and the share link methods only exist on grok.com.

grok.jwt(opts?) ​

Mint the grok.com JWT and cache it until it expires. Returns { token, grokUserId, status, expiresAt }, with token: null and status: "NOT_LINKED" when no grok.com account is linked.

js
const { token, status } = await client.grok.jwt();

grok.rest(route, opts?) ​

Call any grok.com REST route with the JWT. Takes method, body and params.

js
const conv = await client.grok.rest("/rest/app-chat/conversations", { params: { pageSize: 10 } });

grok.home(opts?) / grok.models(opts?) ​

grok.com /rest/modes, or the legacy GrokHome payload with grok_model_options. models() returns just the list.

js
const models = await client.grok.models();

grok.history(opts?) ​

List your Grok conversations.

OptionTypeDescription
opts.countnumberPage size
opts.cursorstringPage token or cursor
opts.querystringgrok.com only, full-text search
opts.starredbooleangrok.com only, pinned conversations
opts.grokCombooleanUse grok.com
js
const page = await client.grok.history({ count: 20 });

grok.conversation(id, opts?) ​

Fetch the responses in a conversation. On x.com, id is the rest id.

js
const conv = await client.grok.conversation("2062645889592938576");

grok.search(query, opts?) ​

Search your Grok conversations. grok.com searches message text. The x.com search op is gone, so on x.com it filters history titles.

js
const results = await client.grok.search("falcon 9");

grok.pinned(opts?) / grok.pin(conversationId, opts?) / grok.unpin(conversationId, opts?) ​

List, pin and unpin conversations. grok.com calls this starring.

js
await client.grok.pin("2062645889592938576");
await client.grok.unpin("2062645889592938576");

grok.rename(conversationId, title, opts?) ​

Rename a grok.com conversation.

grok.deleteConversation(conversationId) ​

Delete a grok.com conversation.

grok.deleteMessage(conversationId, chatItemId) ​

Delete a single message from an x.com conversation. Uses the legacy DeleteGrokMessage mutation.

js
const res = await client.grok.ask("hi");
await client.grok.deleteMessage(res.conversationId, res.agentChatItemId);

grok.mediaHistory(opts?) ​

List your Grok-generated media from grok.com /rest/assets, or the legacy GrokMediaHistory query.

Create, list and revoke grok.com share links.

grok.share(shareId) ​

Resolve a shared Grok conversation by its share id. Uses GrokShare.

js
const shared = await client.grok.share("some_share_id");

grok.clear() ​

Delete all your Grok conversations. Uses grokSettingsClearConversationsMutation.

grok.preferences() / grok.setPreferences(params) ​

Read and update the three Grok data settings: allowGrokMemory, allowXaiDataSharing and allowXaiPersonalization.

js
const prefs = await client.grok.preferences();
await client.grok.setPreferences({ allowGrokMemory: false });

List grok.com accounts that match this X account, and link one with { linkToken, oauthToken } or { authorizationCode }.

grok.tags(opts?) / grok.categories(opts?) ​

Grok tags for the explore page (language, placeId, topicId) and Grok categories for global trending (language).

js
const tags = await client.grok.tags({ language: "en" });

grok.mediaProvenance(tweetId) ​

Media provenance for a post: the first post with the same media, the AI overview and the match count.

grok.mediaMatches(tweetId, opts?) ​

Other posts with the same media. opts.kind is recent (default), similar or mostLiked. Pass cursor from the previous page to continue. Returns { tweets, cursor, raw }.

not affiliated with X Corp.