Environment variables
Typeset requires environment variables for authentication, collaboration, and AI features. Create a.env.local file in your project root:
Required services
All self-hosted Typeset instances require:- Clerk - User authentication and management
- Liveblocks - Real-time collaborative editing
- OpenAI - GPT-4.1-mini AI assistant (default)
- Google AI - Gemini 2.5 Flash AI assistant (alternative)
Clerk authentication
Clerk provides user authentication, session management, and user profiles.Create a Clerk account
Sign up at clerk.com and create a new application.
Get API keys
From your Clerk dashboard:
- Navigate to API Keys in the sidebar
- Copy the Publishable Key (starts with
pk_) - Copy the Secret Key (starts with
sk_)
Clerk automatically handles sign-in, sign-up, and user profile pages. No additional configuration is needed.
Clerk configuration options
Optional Clerk customization: Authentication methods In your Clerk dashboard, enable/disable authentication methods:- Email + password
- Email magic links
- OAuth providers (Google, GitHub, etc.)
- Phone number
- Full name (used in collaboration)
- Email address (used as Liveblocks identifier)
- Profile image (used in editor avatars)
Liveblocks collaboration
Liveblocks enables real-time collaborative editing using Yjs CRDTs.Create a Liveblocks account
Sign up at liveblocks.io and create a new project.
Get API keys
From your Liveblocks dashboard:
- Navigate to API Keys
- Copy the Secret Key (starts with
sk_) - Copy the Public Key (starts with
pk_)
Liveblocks configuration
The Liveblocks integration is configured in:- lib/liveblocks.ts - Server-side client initialization
- liveblocks.config.ts - Type definitions for user awareness
- app/api/liveblocks-auth/route.ts - Authentication endpoint
app/api/liveblocks-auth/route.ts:38-46):
- Real-time cursor positions
- Live document editing with conflict resolution
- Presence indicators (who’s viewing/editing)
- Undo/redo across collaborators
AI configuration (optional)
The AI assistant supports multiple providers. Configure at least one:OpenAI (default)
Used for GPT-4.1-mini model:Get an API key
Create an API key at platform.openai.com.
Google AI
Used for Gemini 2.5 Flash model:Get an API key
Create an API key at ai.google.dev.
Model selection
Users can select models in the UI. The chat API (app/api/chat/route.ts:15-24) handles model routing:
If no AI API keys are configured, the AI assistant will be unavailable but the LaTeX editor will still function.
Complete environment file
Here’s a complete.env.local template:
.env.local
Vercel-specific configuration
If deploying to Vercel, additional analytics services are pre-configured: Vercel Analytics Automatically enabled inapp/layout.tsx:45. No configuration needed - works automatically when deployed to Vercel.
Vercel Speed Insights
Automatically enabled in app/layout.tsx:46. Tracks Web Vitals and performance metrics.
Both services are no-op in local development.
Next.js configuration
Next.js is configured innext.config.ts with:
MDX support
MDX files are supported for documentation:
.js, .jsx, .md, .mdx, .ts, .tsx
Webpack configuration
In development mode, webpack logging is set to error level to suppress cache serialization warnings from syntax highlighting themes.
Tectonic configuration
Tectonic compilation is configured inapp/api/compile/route.ts:
Binary path
Platform-specific paths (route.ts:22-25):
route.ts:8-20):
- Output directory:
os.tmpdir()/out/ - SyncTeX: Disabled (
--synctex=false) - Timeout: 30 seconds (configurable via
maxDuration)
Security best practices
Secure environment variables
- Never commit
.env.localto version control - Use different keys for development and production
- Rotate API keys regularly
- Use Vercel’s encrypted environment variables for production
Verify configuration
Test your configuration:Troubleshooting
Authentication not working
- Verify Clerk keys are correct
- Check
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYis accessible in browser - Ensure protected routes are configured in
middleware.ts - Check Clerk dashboard for error logs
Collaboration not working
- Verify Liveblocks keys are correct
- Check
/api/liveblocks-authreturns 200 status - Ensure
NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEYis set - Check browser console for WebSocket errors
AI assistant not working
- Verify API keys are set correctly
- Check API usage limits in provider dashboards
- Test with curl:
- Check
/api/chatroute returns 200 status
LaTeX compilation failing
- Verify Tectonic binary exists and is executable
- Check
/tmpdirectory permissions - Ensure sufficient disk space for package cache
- Test Tectonic directly:
Next steps
With configuration complete, proceed to:Deploy to production
Deploy to Vercel or your platform using Deployment.