Configuration

Configure API keys, integrations, and environment variables

Nesta Página

Configuration Guide

This guide covers all configuration options for Tarefa AI, including API keys, integrations, and advanced settings.

Environment Variables

Core Configuration

Database

DATABASE_URL="postgresql://postgres:postgres@localhost:5433/claude_scheduler"

For production (Neon, Supabase, etc.):

DATABASE_URL="postgresql://user:password@host.region.aws.neon.tech:5432/dbname?sslmode=require"

Encryption Key

Required for securely storing API keys:

# Generate a secure 64-character hex key
openssl rand -hex 32
ENCRYPTION_KEY="your-64-character-hex-key-here"

AI Provider Configuration

OpenRouter API

OpenRouter provides access to 200+ AI models through a single API:

  1. Create account at OpenRouter.ai
  2. Navigate to Keys
  3. Generate an API key
  4. Add credits (minimum $5)
OPENROUTER_API_KEY="sk-or-v1-xxxxxxxxxxxxxx"
NEXT_PUBLIC_OPENROUTER_API_KEY="sk-or-v1-xxxxxxxxxxxxxx"

Supported Models (25+):

  • Claude Sonnet 4.5, Opus 4, Haiku
  • GPT-5 Pro, GPT-5, o3, o4 Mini, GPT-4o
  • Gemini 2.5 Pro/Flash/Lite
  • Grok 4, Grok 4 Fast
  • DeepSeek V3.1 (FREE)
  • Llama 3.3 70B (FREE)

Notification Services

Email (Resend)

Professional email notifications:

  1. Sign up at Resend.com
  2. Verify your sending domain
  3. Generate API key
RESEND_API_KEY="re_xxxxxxxxxxxx"
RESEND_FROM_EMAIL="notifications@yourdomain.com"

WhatsApp (Evolution API)

Send WhatsApp notifications:

  1. Set up Evolution API instance (self-hosted or cloud)
  2. Create instance and connect WhatsApp number
  3. Generate API key
EVOLUTION_API_URL="https://your-evolution-api.com"
EVOLUTION_API_KEY="your-api-key"
EVOLUTION_INSTANCE="instance-name"

Integration Services

Notion

Post AI results directly to Notion databases:

  1. Go to Notion Integrations
  2. Create new integration
  3. Copy Internal Integration Token
  4. Share your database with the integration
NOTION_API_KEY="ntn_xxxxxxxxxxxx"

Figma

Post comments to Figma files:

  1. Visit Figma Settings
  2. Generate Personal Access Token
  3. Set appropriate scopes (file_read, file_comments:write)
FIGMA_ACCESS_TOKEN="figd-xxxxxxxxxxxx"

Advanced Configuration

Application URL

NEXT_PUBLIC_APP_URL="http://localhost:3000"  # Development
NEXT_PUBLIC_APP_URL="https://your-app.vercel.app"  # Production

Node Environment

NODE_ENV="development"  # or "production"

Scheduler Configuration

# Execute tasks every N seconds (default: 60)
SCHEDULER_INTERVAL_SECONDS="60"
 
# Maximum concurrent task executions
MAX_CONCURRENT_EXECUTIONS="5"

User Configuration (In-App)

Setting Up Your API Key

After installation, configure your OpenRouter API key through the UI:

  1. Navigate to Settings → API Key
  2. Paste your OpenRouter API key
  3. Click "Save & Validate"
  4. Test the connection

The key is encrypted with AES-256-GCM and stored securely in the database.

Notification Preferences

Configure notification channels in Settings → Notifications:

Email Notifications

  • Toggle: Enable/Disable
  • Email address: Verified email
  • Triggers: Task completion, errors, daily summary

WhatsApp Notifications

  • Toggle: Enable/Disable
  • Phone number: International format (+1234567890)
  • Triggers: Task completion, critical errors

Webhooks

  • URL: Your webhook endpoint
  • Secret: For signature verification (HMAC-SHA256)
  • Headers: Custom headers (JSON)

Example webhook payload:

{
  "event": "task.completed",
  "task": {
    "id": 123,
    "name": "Daily Report",
    "status": "completed"
  },
  "execution": {
    "id": 456,
    "output": "AI response here",
    "tokens": 1250,
    "duration_ms": 2340
  },
  "timestamp": "2025-10-17T10:30:00Z"
}

Notion Integration

  • Database ID: From your Notion database URL
  • Properties mapping: Match fields to database properties

Figma Integration

  • File URL: Figma file where comments will be posted
  • Node ID: Specific frame/component (optional)

Security Best Practices

API Key Management

Security Checklist

  • ✅ Use different keys for development and production
  • ✅ Rotate keys every 90 days
  • ✅ Never commit keys to version control
  • ✅ Use environment variables, not hardcoded values
  • ✅ Limit API key permissions to minimum required
  • ✅ Monitor API usage for anomalies

Encryption

All sensitive data is encrypted at rest using AES-256-GCM:

  • User API keys
  • OAuth tokens
  • Webhook secrets
  • Integration credentials

Access Control

Configure user access in the Admin Panel:

  • User activation/deactivation
  • Coupon-based access gating
  • Role-based permissions

Environment-Specific Configuration

Development (.env.local)

DATABASE_URL="postgresql://postgres:postgres@localhost:5433/claude_scheduler"
ENCRYPTION_KEY="dev-only-key-do-not-use-in-production"
OPENROUTER_API_KEY="sk-or-v1-dev-key"
NODE_ENV="development"
NEXT_PUBLIC_APP_URL="http://localhost:3000"

Production (.env.production)

DATABASE_URL="postgresql://user:pass@production-db.neon.tech/dbname?sslmode=require"
ENCRYPTION_KEY="secure-production-key-64-chars-hex"
OPENROUTER_API_KEY="sk-or-v1-production-key"
NODE_ENV="production"
NEXT_PUBLIC_APP_URL="https://your-app.vercel.app"

Configuration Files

next.config.ts

Key configurations:

const config = {
  reactStrictMode: true,
  env: {
    NEXT_PUBLIC_APP_NAME: 'Tarefa AI',
  },
  images: {
    domains: ['avatars.githubusercontent.com'],
  },
};

drizzle.config.ts

Database connection configuration:

export default {
  schema: './db/schema.ts',
  out: './drizzle',
  driver: 'pg',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL!,
  },
};

Validation

Test Configuration

Verify all configurations are working:

# Test database connection
npm run db:studio
 
# Test OpenRouter API
curl -X POST https://openrouter.ai/api/v1/models \
  -H "Authorization: Bearer $OPENROUTER_API_KEY"
 
# Test email (Resend)
curl -X POST https://api.resend.com/emails \
  -H "Authorization: Bearer $RESEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"from": "test@yourdomain.com", "to": "you@example.com", "subject": "Test", "html": "<p>Test email</p>"}'
 
# Test application health
curl http://localhost:3000/api/health

Troubleshooting

Configuration Issues

Invalid API Key

Error: Unauthorized (401)

Solution: Verify API key is correct and has proper permissions.

Database Connection Failed

Error: Connection terminated unexpectedly

Solution: Check DATABASE_URL format, credentials, and SSL mode.

Encryption Key Invalid

Error: Invalid key length

Solution: Encryption key must be exactly 64 hexadecimal characters.

Environment Variables Not Loading

  1. Check file name: .env.local (note the dot prefix)
  2. Restart development server after changes
  3. Verify no typos in variable names
  4. Check for proper quote usage
# Correct
DATABASE_URL="postgresql://..."
 
# Incorrect (missing quotes)
DATABASE_URL=postgresql://...

Next Steps

With your configuration complete, you're ready to: