Skip to content

Fix OpenAI API Key Configuration in .env File #3069

@actuallyrizzn

Description

@actuallyrizzn

Issue: OpenAI API Key Configuration in .env File

Problem

When setting up the Letta server via the installer, the .env file may be created with quoted values for API keys. This causes the server to fail when attempting to use OpenAI API keys, resulting in 500 errors when creating agents.

Root Causes

  1. Quoted Environment Variables

    • Docker's --env-file flag includes quotes as part of the environment variable value
    • If .env contains: OPENAI_API_KEY="sk-proj-..."
    • Docker sets: OPENAI_API_KEY="sk-proj-..." (with quotes in the value)
    • This causes OpenAI API to reject requests with "Invalid authorization header"
  2. Missing LETTA_ENCRYPTION_KEY

    • Letta's Secret class requires LETTA_ENCRYPTION_KEY to be set, even if encryption is not actively used
    • Without it, the Secret class may incorrectly identify API keys as encrypted and fail to decrypt them
    • This results in None being returned instead of the actual API key

Required Fixes

  1. Ensure .env file format does not include quotes around values:

    # ✅ Correct
    OPENAI_API_KEY=sk-proj-abc123...
    
    # ❌ Incorrect
    OPENAI_API_KEY="sk-proj-abc123..."
  2. Ensure LETTA_ENCRYPTION_KEY is set in .env:

    LETTA_ENCRYPTION_KEY=dummy-encryption-key-32-chars-long!!

    Note: This is required even if encryption is not being used.

Impact

  • Severity: High
  • User Impact: Server cannot authenticate with OpenAI API, agent creation fails
  • Workaround: Manual editing of .env file after installation

References

See detailed incident report for full technical details and investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions