Repository: topoteretes/cognee
File: cognee/api/health.py (Python)

Code before:
                details=f"Storage test failed: {str(e)}",
            )

    async def check_llm_provider(self) -> ComponentHealth:
        """Check LLM provider health (non-critical)."""
        start_time = time.time()
        try:
            from cognee.infrastructure.llm.get_llm_client import get_llm_client
            from cognee.infrastructure.llm.config import get_llm_config

            config = get_llm_config()

            # Test actual API connection with minimal request
            client = get_llm_client()
            await client.acomplete("test", max_tokens=1)

            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.HEALTHY,
                provider=config.llm_provider,
                response_time_ms=response_time,
                details="API responding",
            )
        except Exception as e:
            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.DEGRADED,
                provider="unknown",
                response_time_ms=response_time,
                details=f"API check failed: {str(e)}",
            )

    async def check_embedding_service(self) -> ComponentHealth:
        """Check embedding service health (non-critical)."""
        start_time = time.time()
        try:
            from cognee.infrastructure.databases.vector.embeddings.get_embedding_engine import (
                get_embedding_engine,
            )

            # Test actual embedding generation with minimal text
            engine = get_embedding_engine()
            await engine.embed_text("test")

            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.HEALTHY,
                provider="configured",
                response_time_ms=response_time,
                details="Embedding generation working",
            )

Review comment (bug):
```suggestion
            response_time = int((time.time() - start_time) * 1000)
            logger.error(f"LLM provider health check failed: {str(e)}", exc_info=True)
            return ComponentHealth(
```

Code after:
                status=HealthStatus.UNHEALTHY,
                provider="unknown",
                response_time_ms=response_time,
                details=f"Storage test failed: {str(e)}",
            )

    async def check_llm_provider(self) -> ComponentHealth:
        """Check LLM provider health (non-critical)."""
        start_time = time.time()
        try:
            from cognee.infrastructure.llm.get_llm_client import get_llm_client
            from cognee.infrastructure.llm.config import get_llm_config

            config = get_llm_config()

            # Test actual API connection with minimal request
            client = get_llm_client()
            await client.show_prompt("test", "test")

            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.HEALTHY,
                provider=config.llm_provider,
                response_time_ms=response_time,
                details="API responding",
            )
        except Exception as e:
            response_time = int((time.time() - start_time) * 1000)
            logger.error(f"LLM provider health check failed: {str(e)}", exc_info=True)
            return ComponentHealth(
                status=HealthStatus.DEGRADED,
                provider="unknown",
                response_time_ms=response_time,
                details=f"API check failed: {str(e)}",
            )

    async def check_embedding_service(self) -> ComponentHealth:
        """Check embedding service health (non-critical)."""
        start_time = time.time()
        try:
            from cognee.infrastructure.databases.vector.embeddings.get_embedding_engine import (
                get_embedding_engine,
            )

            # Test actual embedding generation with minimal text
            engine = get_embedding_engine()
            await engine.embed_text("test")

            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.HEALTHY,