Max AI doesn't work out-of-the-box on self-hosted PostHog. Two things are broken:

  1. Web Web container can't reach Temporal
  2. No worker listening on the max-ai-task-queue

Prerequisites

Get an API key from OpenAI & Anthropic (yes, you need both):

Fixing it Add Temporal host to web service:

  1. We need to add the temporal host to the web service, to do so, you edit the docker-compose.yml file and add this environment:
web:
  environment:
    TEMPORAL_HOST: 'temporal'
  1. We need to create the AI worker, to do so add this service to your docker-compose.yml:
temporal-django-worker-max-ai:
    command: /compose/temporal-django-worker
    extends:
        file: docker-compose.base.yml
        service: temporal-django-worker
    volumes:
        - ./compose:/compose
    image: $REGISTRY_URL:$POSTHOG_APP_TAG
    environment:
        SITE_URL: https://$DOMAIN
        SECRET_KEY: $POSTHOG_SECRET
        TEMPORAL_TASK_QUEUE: max-ai-task-queue
        OPENAI_API_KEY: 'your-key-here'
        # or ANTHROPIC_API_KEY: 'your-key-here'
    depends_on:
        - db
        - redis
        - clickhouse
        - kafka
        - objectstorage
        - seaweedfs
        - temporal
  1. Last thing to do is to start the new service & restart the web service to apply the changes:
docker-compose up -d --force-recreate web temporal-django-worker-max-ai

Done. PostHog AI should work now.

There's currently a PR that should make the process much easier by just setting the environment variables needed + a guide on the official PostHog website:

feat: add Max AI worker and setup documentation for hobby deployments by Vitor-Bukovitz · Pull Request #45601 · PostHog/posthog
Problem Self-hosted hobby deployments cannot use Max AI (PostHog's AI assistant) because: The web container tries to connect to Temporal at 127.0.0.1:7233 instead of the temporal Docker servic…