AI Assistant Configuration
The AI Assistant is Loggator’s most powerful feature, enabling natural language queries and automated log analysis.
Overview
Section titled “Overview”The AI Assistant can:
- Search logs using natural language
- Analyze container health
- Explain errors and suggest solutions
- Filter logs by time, container, or stream
- Aggregate and summarize log patterns
1. Get an OpenRouter API Key
Section titled “1. Get an OpenRouter API Key”OpenRouter provides access to multiple AI models through a single API:
- Visit OpenRouter.ai
- Sign up for a free account
- Go to Keys
- Create a new API key
- Copy the key (starts with
sk-or-v1-)
2. Configure Environment Variables
Section titled “2. Configure Environment Variables”Add to your .env file:
OPENROUTER_API_KEY=sk-or-v1-your-key-hereAI_MODEL=xiaomi/mimo-v2-flash:freeSITE_URL=http://localhost:30003. Restart Loggator
Section titled “3. Restart Loggator”docker compose restart loggatorThe AI chat will now be available in the UI!
Model Selection
Section titled “Model Selection”Free Models
Section titled “Free Models”Perfect for getting started and most log analysis tasks:
xiaomi/mimo-v2-flash:free (Recommended)
Section titled “xiaomi/mimo-v2-flash:free (Recommended)”- Speed: Very fast
- Quality: Good for log analysis
- Best for: Quick queries, error detection
- Rate Limits: Generous free tier
AI_MODEL: xiaomi/mimo-v2-flash:freegoogle/gemini-2.0-flash-thinking-exp:free
Section titled “google/gemini-2.0-flash-thinking-exp:free”- Speed: Fast
- Quality: Excellent reasoning
- Best for: Complex analysis, troubleshooting
- Rate Limits: Moderate
AI_MODEL: google/gemini-2.0-flash-thinking-exp:freemeta-llama/llama-3.2-3b-instruct:free
Section titled “meta-llama/llama-3.2-3b-instruct:free”- Speed: Very fast
- Quality: Good for simple queries
- Best for: Basic log search
- Rate Limits: High
AI_MODEL: meta-llama/llama-3.2-3b-instruct:freePaid Models
Section titled “Paid Models”For production use with high volumes:
anthropic/claude-3.5-sonnet
Section titled “anthropic/claude-3.5-sonnet”- Speed: Moderate
- Quality: Excellent
- Best for: Complex analysis, detailed explanations
- Cost: ~$3 per 1M input tokens
AI_MODEL: anthropic/claude-3.5-sonnetopenai/gpt-4-turbo
Section titled “openai/gpt-4-turbo”- Speed: Moderate
- Quality: Very good
- Best for: General purpose
- Cost: ~$10 per 1M input tokens
AI_MODEL: openai/gpt-4-turbogoogle/gemini-pro-1.5
Section titled “google/gemini-pro-1.5”- Speed: Fast
- Quality: Good
- Best for: High volume, cost-effective
- Cost: ~$3.50 per 1M input tokens
AI_MODEL: google/gemini-pro-1.5Available Tools
Section titled “Available Tools”The AI assistant has access to these tools:
search_logs
Section titled “search_logs”Search container logs with filters.
Parameters:
query(required): Search termscontainer(optional): Filter by container namestream(optional):stdoutorstderrlimit(optional): Max results (default: 50, max: 100)
Example Query:
“Show me all errors from nginx in the last hour”
list_containers
Section titled “list_containers”List all monitored Docker containers.
Parameters:
all(optional): Include stopped containers
Example Query:
“What containers are you monitoring?“
get_container_info
Section titled “get_container_info”Get detailed information about a specific container.
Parameters:
containerName(required): Container name
Example Query:
“Tell me about the api container”
analyze_container_health
Section titled “analyze_container_health”Analyze container health based on recent logs.
Parameters:
containerName(required): Container nameminutes(optional): Time window (default: 60, max: 1440)
Example Query:
“Is my web container healthy?”
Example Queries
Section titled “Example Queries”Basic Search
Section titled “Basic Search”Show me recent logsFind errorsWhat's in the logs from nginx?Time-Based
Section titled “Time-Based”Show errors from the last 2 hoursWhat happened in the last 30 minutes?Any warnings today?Container-Specific
Section titled “Container-Specific”Show me logs from the api containerWhat errors does the database container have?Is the web server working correctly?Stream Filtering
Section titled “Stream Filtering”Show me stderr logsAny errors in the error stream?What's in stdout for the api container?Health Analysis
Section titled “Health Analysis”Is the api container healthy?Analyze the web containerCheck for problems in nginxWhat's wrong with my database?Complex Queries
Section titled “Complex Queries”Show me all 500 errors from the api container in the last hourFind connection timeout errorsWhat containers are logging errors?Analyze patterns in the nginx access logsChat Features
Section titled “Chat Features”Persistent History
Section titled “Persistent History”Your chat history is saved automatically:
- Conversations persist across browser sessions
- Context is maintained for follow-up questions
- Clear history button available
Markdown Formatting
Section titled “Markdown Formatting”Responses include:
- Code blocks with syntax highlighting
- Tables for structured data
- Lists for multiple items
- Bold/Italic for emphasis
Tool Calling Visibility
Section titled “Tool Calling Visibility”Watch the AI work:
- See which tools are being called
- View tool parameters
- Inspect tool results
Usage Limits
Section titled “Usage Limits”Free Tier
Section titled “Free Tier”OpenRouter free models typically include:
- Rate limits: 10-20 requests/minute
- Daily quotas: 100-200 requests/day
- Response size limits
Paid Tier
Section titled “Paid Tier”Paid models offer:
- Higher rate limits
- No daily quotas
- Priority access
- Better performance
Cost Optimization
Section titled “Cost Optimization”1. Use Free Models
Section titled “1. Use Free Models”Free models are sufficient for most log analysis:
AI_MODEL: xiaomi/mimo-v2-flash:free2. Be Specific
Section titled “2. Be Specific”More specific queries = less token usage:
❌ “Tell me everything about my logs” ✅ “Show errors from nginx in the last hour”
3. Limit Results
Section titled “3. Limit Results”Request only what you need:
❌ “Show me all logs” (thousands of results) ✅ “Show me the last 20 error logs”
4. Use Direct Search
Section titled “4. Use Direct Search”For simple searches, use the search page instead of AI:
- Faster response
- No API costs
- Full Meilisearch power
Security
Section titled “Security”API Key Protection
Section titled “API Key Protection”- Never commit keys to version control
- Use
.envfiles (add to.gitignore) - Rotate keys regularly
- Use separate keys per environment
Data Privacy
Section titled “Data Privacy”Logs sent to OpenRouter:
- Are processed by the AI model
- May be used for model improvement (check provider policy)
- Should not contain sensitive data
Label-Based Access Control
Section titled “Label-Based Access Control”The AI can only access containers with the monitoring label:
DOCKER_LABEL_FILTER: loggator.enable=trueThis prevents unauthorized access to sensitive containers.
Troubleshooting
Section titled “Troubleshooting””AI features disabled”
Section titled “”AI features disabled””Check:
OPENROUTER_API_KEYis set- Key is valid and active
- Loggator was restarted after adding the key
# Verify environment variabledocker exec loggator env | grep OPENROUTER_API_KEY
# Restartdocker compose restart loggator”Rate limit exceeded”
Section titled “”Rate limit exceeded””Solutions:
- Wait for the limit to reset (usually 1 minute)
- Upgrade to a paid model
- Use direct search for simple queries
Poor responses
Section titled “Poor responses”Try:
- Be more specific in your query
- Try a different model
- Check if logs are being indexed:
http://localhost:3000/search
Slow responses
Section titled “Slow responses”Causes:
- Model is slow (try a “flash” variant)
- Large result sets (limit your query)
- High load on OpenRouter
Solutions:
# Switch to a faster modelAI_MODEL: xiaomi/mimo-v2-flash:free # Very fast
# OrAI_MODEL: google/gemini-pro-1.5 # Fast paid optionAdvanced Configuration
Section titled “Advanced Configuration”Custom System Prompt
Section titled “Custom System Prompt”The system prompt is defined in the source code. To customize:
- Fork the repository
- Edit
src/routes/api/chat/+server.ts - Modify the
SYSTEM_MESSAGEconstant - Rebuild and deploy
Multiple AI Models
Section titled “Multiple AI Models”Run multiple Loggator instances with different models:
services: loggator-free: image: ghcr.io/mbeggiato/loggator:latest ports: - "3000:3000" environment: AI_MODEL: xiaomi/mimo-v2-flash:free
loggator-premium: image: ghcr.io/mbeggiato/loggator:latest ports: - "3001:3000" environment: AI_MODEL: anthropic/claude-3.5-sonnetMonitoring API Usage
Section titled “Monitoring API Usage”Check OpenRouter dashboard for:
- Request counts
- Token usage
- Costs (for paid models)
- Rate limit status
Next Steps
Section titled “Next Steps”- Log Search - Manual search without AI
- API Reference - Integrate AI chat in your apps
- Container Monitoring - Dashboard features