xAI's Grok
Set up Grok & understand how it’s used in the Twitter Brand Personality Generator
Read through this guide to set up xAI’s Grok API & get familiar with how it is used in the Twitter Brand Personality Generator.
Set up Grok API
First, create an account or sign in at the xAI Console. Next, navigate to the “API Keys” section and click “Create new API key”. Make sure to save your API key somewhere safe and do not share it with anyone.
Once you have your API key, paste it in your .env file:
Demo App
The Twitter Brand Personality Generator showcases Grok’s capabilities in analyzing brand voice and generating engaging social media content.
Twitter Brand Personality Generator
Generate Twitter brand personalities with tone analysis, example tweets, and risk assessment
Structure
The API route in app/api/(apps)/grok/route.ts
follows this structure:
- Takes in brand details from the front-end
- Generates a prompt based on the brand inputs
- Calls Grok API using the prompt + JSON schema
- Extracts the structured JSON response containing:
- Brand tone scores
- Common phrases and emojis
- Example tweets with engagement metrics
- PR risk analysis
- Stores the response in Supabase
- Returns a
uuid
to the front-end for fetching & displaying the analysis
More information on the codebase structure can be found here:
Structure
Understand the project structure of the codebase
API Response Structure
The Grok API returns structured JSON containing:
The structured output enables rich visualizations including radar charts for tone analysis, Twitter-style cards for example tweets, and risk assessment indicators.