microsoft/semantic-kernel · error · ServiceResponseException

Astra DB not available. Status : {response}

Error message

Astra DB not available. Status : {response}

What it means

Raised by `AstraClient._run_query` when the HTTP response status is not 200. Unlike the 200-with-errors case, this indicates the request never succeeded at the transport/HTTP layer. The full response object (including its status) is embedded in the `ServiceResponseException` message.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/astradb/astra_client.py:59

        )
        self.request_header = {
            "x-cassandra-token": self.astra_application_token,
            "Content-Type": "application/json",
            "User-Agent": ASTRA_CALLER_IDENTITY,
        }
        self._session = session

    async def _run_query(self, request_url: str, query: dict):
        async with (
            AsyncSession(self._session) as session,
            session.post(request_url, data=json.dumps(query), headers=self.request_header) as response,
        ):
            if response.status == 200:
                response_dict = await response.json()
                if "errors" in response_dict:
                    raise ServiceResponseException(f"Astra DB request error - {response_dict['errors']}")
                return response_dict
            raise ServiceResponseException(f"Astra DB not available. Status : {response}")

    async def find_collections(self, include_detail: bool = True):
        """Finds all collections in the keyspace."""
        query = {"findCollections": {"options": {"explain": include_detail}}}
        result = await self._run_query(self.request_base_url, query)
        return result["status"]["collections"]

    async def find_collection(self, collection_name: str):
        """Finds a collection in the keyspace."""
        collections = await self.find_collections(False)
        found = False
        for collection in collections:
            if collection == collection_name:
                found = True
                break
        return found

    async def create_collection(

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Check the embedded status code: 401/403 -> rotate/fix the app token; 404 -> verify db id/region/endpoint URL; 429 -> back off and retry; 5xx -> retry with backoff or check Astra status page.
  2. Regenerate the Astra application token and confirm `ASTRA_DB_APP_TOKEN` / the token arg is current.
  3. Verify the Astra database id and region used to build `AstraDBSettings`.
  4. Retry transient failures (5xx, 429) with exponential backoff; treat 4xx (except 429) as permanent.
  5. Ensure no proxy is intercepting the request with a non-200 status.

Example fix

// before
client = AstraClient(..., astra_application_token=stale_token)
await client.find_collections()

// after
client = AstraClient(..., astra_application_token=fresh_token)
try:
    await client.find_collections()
except ServiceResponseException as e:
    if "Status : <Response ... 401>" in str(e):
        raise RuntimeError("refresh Astra token") from e
    raise
Defensive patterns

Strategy: retry

Validate before calling

# validate connectivity/config before heavy use
import aiohttp
async def astra_reachable(base_url, token):
    headers = {"X-Cassandra-Token": token}
    async with aiohttp.ClientSession() as s:
        async with s.post(base_url, headers=headers, json={}) as r:
            return r.status == 200 or r.status == 400  # 400 still means reachable

Try / catch

from semantic_kernel.exceptions import ServiceResponseException
import asyncio

async def call_with_retry(fn, *a, **kw):
    for attempt in range(5):
        try:
            return await fn(*a, **kw)
        except ServiceResponseException as e:
            s = str(e)
            if "Status" in s and any(c in s for c in ("401", "403", "404")):
                raise  # permanent
            await asyncio.sleep(2 ** attempt)  # 5xx/429 -> backoff
    raise

Prevention

When it happens

Trigger: Astra REST API returns a non-200 status for any query: 401/403 for auth/token problems, 404 for a wrong base URL or API path, 429 for rate limiting, 5xx for Astra outages, or a connection that resolves to a different host returning an arbitrary status.

Common situations: Expired or invalid Astra application token (401/403); wrong database id/region in the request URL (404); Astra regional outage or maintenance window (5xx); rate limit exceeded (429); corporate proxy/firewall returning a blocking status; DNS misconfiguration.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/bd1be950d1d3f8bb. Report an issue: GitHub.