Langfuse Authentication Troubleshooting Guide
Quick Debugging Steps
- Visit the debug page: Navigate to
/debug/langfusein your app - Check the browser console: Look for detailed logs starting with
[LangfuseTracing] - Test the API endpoint: Visit
/api/debug/langfuseto check server-side configuration - Run console commands:
debugLangfuseStatus() testLangfuseConnection()
Common Issues and Solutions
1. Public Key Not Found
Symptoms:
- Console shows: “Langfuse not initialized - no public key available”
debugLangfuseStatus()showshasPublicKey: false
Solutions:
For Local Development:
- Check your
.env.localfile has:NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY=your-actual-key-here - Ensure the key starts with
pk-(public key) or similar prefix - Restart your development server after adding/changing env vars:
npm run dev
For Production Deployment: Environment variables must be added to GCP Secret Manager:
- Download current secrets:
gcloud secrets versions access latest --secret=FIREBASE_ENV --project YOUR_PROJECT_ID > .env.local - Add/update the variables in
.env.local - Upload back to Secret Manager:
gcloud secrets versions add FIREBASE_ENV --data-file=.env.local --project YOUR_PROJECT_ID - Redeploy frontend to pick up new secrets
2. Wrong Key Format
Symptoms:
- Console warning: “Public key format may be incorrect”
- Authentication failures despite key being present
Solutions:
- Verify your Langfuse public key format:
- Should look like:
pk-lf-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - Contains dashes/hyphens
- Is the PUBLIC key, not the secret key
- Should look like:
- Check you haven’t accidentally used the secret key as the public key
3. Base URL Issues
Symptoms:
- Connection timeouts or 404 errors
- Using default URL when you have a custom instance
Solutions:
- For Langfuse Cloud (default):
NEXT_PUBLIC_LANGFUSE_BASE_URL=https://cloud.langfuse.com - For self-hosted:
NEXT_PUBLIC_LANGFUSE_BASE_URL=https://your-langfuse-instance.com - Ensure the URL doesn’t have a trailing slash
4. Client vs Server Issues
Symptoms:
- Works on server but not client, or vice versa
- Different behavior in development vs production
Solutions:
Environment Variable Configuration:
Local Development (.env.local):
# Client-side variables (available in browser)
NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY=xxx
NEXT_PUBLIC_LANGFUSE_BASE_URL=xxx
# Server-side variables (API routes only)
LANGFUSE_SECRET_KEY=xxx
Production Deployment:
All variables above must be added to GCP Secret Manager under FIREBASE_ENV secret. See production deployment steps in the previous troubleshooting section.
Debug Configuration: Use the debug API endpoint to check server config:
curl http://localhost:3000/api/debug/langfuse
5. Build vs Runtime Configuration
Symptoms:
- Environment variables not updating after changes
- Works locally but not in production
Solutions:
- For local development, restart the dev server
- For production, rebuild the application:
npm run build npm start - Check if using runtime config in
next.config.mjs:publicRuntimeConfig: { NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY: process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY, NEXT_PUBLIC_LANGFUSE_BASE_URL: process.env.NEXT_PUBLIC_LANGFUSE_BASE_URL }
Debugging Commands
Browser Console Commands
// Check current status
debugLangfuseStatus()
// Test the connection
await testLangfuseConnection()
// Manual trace test
const traceId = langfuseTracing.createTrace({ name: 'manual-test' })
langfuseTracing.addEvent('test-event', { data: 'test' })
langfuseTracing.endTrace()
API Debug Endpoint
# Check server-side configuration
curl http://localhost:3000/api/debug/langfuse
# Pretty print the JSON response
curl http://localhost:3000/api/debug/langfuse | jq
Configuration Checklist
.env.localfile exists and contains Langfuse keys- Public key starts with correct prefix (e.g.,
pk-) - Public key is in
NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY(note theNEXT_PUBLIC_prefix) - Base URL is correctly set (default:
https://cloud.langfuse.com) - Dev server restarted after env changes
- No trailing slashes in URLs
- Keys don’t contain extra spaces or quotes
- Using the correct key (public vs secret)
- For production: Environment variables are set in hosting platform
Still Having Issues?
- Check the Langfuse dashboard for any error messages
- Verify your Langfuse project settings
- Test with a minimal example:
import { Langfuse } from 'langfuse'; const langfuse = new Langfuse({ publicKey: 'your-key-here', baseUrl: 'https://cloud.langfuse.com' }); const trace = langfuse.trace({ name: 'test' }); trace.event({ name: 'test-event' }); - Check network requests in browser DevTools for failed API calls
- Look for CORS errors or blocked requests
Contact Support
If none of the above solutions work:
- Gather debug information using
debugLangfuseStatus() - Check browser console for error messages
- Test the API debug endpoint
- Contact Langfuse support with the debug output