> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brainstormer.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment & Configuration

> Environment variables, API keys, service-key mapping, agent configuration variables, and platform config reference.

## Required API Keys

<Warning>
  These keys are required for core functionality. The platform will not work without them.
</Warning>

| Key                  | Purpose                                                 | Get It At                                                                    |
| -------------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `OPENROUTER_API_KEY` | Access to 300+ AI models (GPT-4, Claude, Gemini, Llama) | [https://openrouter.ai/keys](https://openrouter.ai/keys)                     |
| `OPENAI_API_KEY`     | Embeddings for Knowledge Base System                    | [https://platform.openai.com/api-keys](https://platform.openai.com/api-keys) |

## Optional API Keys

| Key                   | Purpose                                             | Get It At                                                                                                  |
| --------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `ANTHROPIC_API_KEY`   | Direct Claude access (alternative to OpenRouter)    | [https://console.anthropic.com/](https://console.anthropic.com/)                                           |
| `ELEVENLABS_API_KEY`  | Voice cloning and text-to-speech                    | [https://elevenlabs.io/app/speech-synthesis/api-keys](https://elevenlabs.io/app/speech-synthesis/api-keys) |
| `LLAMA_CLOUD_API_KEY` | Advanced document parsing via LlamaParse            | [https://cloud.llamaindex.ai/api-key](https://cloud.llamaindex.ai/api-key)                                 |
| `PINECONE_API_KEY`    | Production vector database (falls back to ChromaDB) | [https://www.pinecone.io/](https://www.pinecone.io/)                                                       |
| `GEMINI_API_KEY`      | Gemini multimodal embeddings                        | [https://aistudio.google.com/apikey](https://aistudio.google.com/apikey)                                   |

## Service-Key Mapping

| Service               | Port | Required Keys        | Optional Keys                                               |
| --------------------- | ---- | -------------------- | ----------------------------------------------------------- |
| **Bot Service**       | 4002 | `OPENROUTER_API_KEY` | `ANTHROPIC_API_KEY`                                         |
| **Knowledge Service** | 4005 | `OPENAI_API_KEY`     | `LLAMA_CLOUD_API_KEY`, `PINECONE_API_KEY`, `GEMINI_API_KEY` |
| **Realtime Audio**    | 4003 | None                 | `ELEVENLABS_API_KEY`                                        |
| **Auth Service**      | 4001 | None                 | `RESEND_API_KEY`                                            |
| **Gateway**           | 4000 | None                 | None                                                        |
| **Web App**           | 3000 | None                 | None                                                        |

## Full Environment Reference

<Tabs>
  <Tab title="Database & Infrastructure">
    ```bash theme={null}
    # PostgreSQL (Docker container)
    DATABASE_URL=postgresql://brainstormer:password@localhost:5432/brainstormer

    # Redis (Docker container)
    REDIS_HOST=localhost
    REDIS_PORT=6379
    REDIS_PASSWORD=

    # ChromaDB
    CHROMA_HOST=localhost
    CHROMA_PORT=8000
    ```
  </Tab>

  <Tab title="AI & Embeddings">
    ```bash theme={null}
    # OpenRouter (REQUIRED)
    OPENROUTER_API_KEY=sk-or-v1-...
    OPENROUTER_BASE_URL=https://openrouter.ai/api/v1

    # OpenAI (REQUIRED for embeddings)
    OPENAI_API_KEY=sk-...

    # Gemini Embeddings
    GEMINI_API_KEY=...
    EMBEDDING_MODEL=gemini-embedding-exp-03-07
    EMBEDDING_DIMENSIONS=3072

    # Default AI model
    DEFAULT_MODEL=google/gemini-2.0-flash-001
    PLATFORM_INTELLIGENCE_MODEL=anthropic/claude-3-haiku
    ```
  </Tab>

  <Tab title="Service Ports">
    ```bash theme={null}
    GATEWAY_PORT=4000
    AUTH_SERVICE_PORT=4001
    BOT_SERVICE_PORT=4002
    REALTIME_AUDIO_PORT=4003
    KNOWLEDGE_SERVICE_PORT=4005
    ```
  </Tab>

  <Tab title="Authentication">
    ```bash theme={null}
    JWT_SECRET=your-super-secret-jwt-key
    JWT_EXPIRES_IN=24h
    JWT_REFRESH_EXPIRES_IN=7d
    BCRYPT_ROUNDS=12

    # Superadmin access
    PLATFORM_SUPERADMIN_EMAILS=admin@brainstormer.ai
    NEXT_PUBLIC_PLATFORM_SUPERADMIN_EMAILS=admin@brainstormer.ai
    ```
  </Tab>

  <Tab title="Email">
    ```bash theme={null}
    RESEND_API_KEY=re_...
    EMAIL_FROM=noreply@brainstormer.ai
    WEB_APP_URL=https://bsio2.brainstormer.io
    ```
  </Tab>

  <Tab title="Cloud Storage">
    ```bash theme={null}
    CLOUD_STORAGE_ENABLED=false
    CLOUD_STORAGE_PROVIDER=aws-s3
    CLOUD_STORAGE_BUCKET=your-bucket-name
    CLOUD_STORAGE_REGION=us-east-1
    CLOUD_STORAGE_ACCESS_KEY_ID=...
    CLOUD_STORAGE_SECRET_ACCESS_KEY=...
    ```
  </Tab>

  <Tab title="Vector Database">
    ```bash theme={null}
    # Pinecone (production)
    PINECONE_API_KEY=...
    PINECONE_ENVIRONMENT=us-east-1
    PINECONE_INDEX_NAME=brainstormer-kb

    # Processing
    CHUNK_SIZE=1000
    CHUNK_OVERLAP=200
    MAX_CONCURRENT_JOBS=5
    ```
  </Tab>

  <Tab title="Voice & Audio">
    ```bash theme={null}
    ELEVENLABS_API_KEY=...
    LIVEKIT_API_KEY=...
    LIVEKIT_API_SECRET=...
    LIVEKIT_URL=wss://...
    ```
  </Tab>

  <Tab title="Observability">
    ```bash theme={null}
    LANGSMITH_TRACING=true
    LANGSMITH_API_KEY=...
    LANGSMITH_PROJECT=brainstormer

    MODEL_SYNC_ENABLED=true
    MODEL_SYNC_INTERVAL_MINUTES=60
    ```
  </Tab>
</Tabs>

## Agent Configuration Variables

These frontend-facing configuration variables control agent creation and validation:

### Agent Name Validation

| Variable                          | Default | Description               |
| --------------------------------- | ------- | ------------------------- |
| `NEXT_PUBLIC_BOT_NAME_MIN_LENGTH` | 3       | Minimum agent name length |
| `NEXT_PUBLIC_BOT_NAME_MAX_LENGTH` | 50      | Maximum agent name length |

### Agent Prompt Validation

| Variable                                   | Default | Description              |
| ------------------------------------------ | ------- | ------------------------ |
| `NEXT_PUBLIC_BOT_SYSTEM_PROMPT_MAX_LENGTH` | 1000    | Max system prompt length |
| `NEXT_PUBLIC_BOT_DESCRIPTION_MAX_LENGTH`   | 200     | Max description length   |

### Agent UI

| Variable                             | Default | Description                  |
| ------------------------------------ | ------- | ---------------------------- |
| `NEXT_PUBLIC_BOT_MAX_MODELS_DISPLAY` | 8       | Models shown in selection UI |

### Template Default Models

| Variable                                          | Default                     |
| ------------------------------------------------- | --------------------------- |
| `NEXT_PUBLIC_BOT_TEMPLATE_CUSTOMER_SUPPORT_MODEL` | `anthropic/claude-3-haiku`  |
| `NEXT_PUBLIC_BOT_TEMPLATE_KNOWLEDGE_MODEL`        | `openai/gpt-4o-mini`        |
| `NEXT_PUBLIC_BOT_TEMPLATE_CREATIVE_MODEL`         | `anthropic/claude-3-sonnet` |
| `NEXT_PUBLIC_BOT_TEMPLATE_CODING_MODEL`           | `openai/gpt-4o`             |

<Note>
  Configuration keys maintain `BOT_` prefix for backward compatibility during transition from "bots" to "agents" terminology.
</Note>

## What Won't Work Without Keys

| Missing Key           | Impact                                                                     |
| --------------------- | -------------------------------------------------------------------------- |
| `OPENROUTER_API_KEY`  | Cannot chat with AI agents, model sync disabled, agent testing unavailable |
| `OPENAI_API_KEY`      | Knowledge Base embeddings won't work, document upload/search disabled      |
| `ELEVENLABS_API_KEY`  | Voice cloning features disabled                                            |
| `LLAMA_CLOUD_API_KEY` | Falls back to open-source parsers for document processing                  |
| `PINECONE_API_KEY`    | Falls back to ChromaDB (local) for vector storage                          |

## Cost Estimates (Monthly)

### Required (Minimal Usage)

| Service           | Cost                                            |
| ----------------- | ----------------------------------------------- |
| OpenRouter        | \$0-5/month (pay per use, includes free models) |
| OpenAI Embeddings | \~\$0.10 per 1M tokens                          |

### Optional

| Service    | Cost                              |
| ---------- | --------------------------------- |
| Anthropic  | \$0-20/month                      |
| ElevenLabs | Free tier (10k chars/month)       |
| LlamaParse | Free tier (1k pages/day)          |
| Pinecone   | Free tier (1 index, 100k vectors) |

## Platform Config (DB-Stored)

In addition to environment variables, API keys and settings can be stored in the `platform_config` database table, managed via the admin UI at `/admin`. DB values take precedence over env vars.

**Categories:** `ai`, `voice`, `knowledge`, `feature_flags`

**Managed keys include:** OPENROUTER, OPENAI, ELEVENLABS, LIVEKIT, PINECONE, GEMINI, and more.

## Security Notes

* Never commit `.env` to git (already in `.gitignore`)
* Use different keys for development and production
* Rotate keys regularly if exposed
* Monitor usage on provider dashboards
* Sensitive platform config values are encrypted with AES-256-GCM
