BerriAI/litellm · error · Exception
Failed to get branches
Error message
Failed to get branches: {e} What it means
Raised by BitBucketClient.get_branches when any exception occurs during GET /repositories/{workspace}/{repository}/refs/branches. Like get_repository_info, it wraps everything into one message: HTTP status errors (404 wrong repo, 401 bad token, 403 no permission, 429 rate limit), network failures, and JSON decode errors all surface identically.
Solutions
- Run test_connection() first — if it returns False, fix auth/workspace/repo before debugging branches
- Confirm the branch name and repo slugs with: curl -H "Authorization: Bearer $TOKEN" "https://api.bitbucket.org/2.0/repositories/<ws>/<repo>/refs/branches"
- Check whether the token was rotated or expired and update the config
- Retry with backoff if the wrapped cause indicates 429/5xx
Defensive patterns
Strategy: try-catch
Validate before calling
if not client.test_connection():
raise RuntimeError("fix auth/repo config before listing branches") Try / catch
try:
branches = client.get_branches()
except Exception as e:
# everything (404/401/403/network) lands here; test_connection() disambiguates auth vs repo
raise Prevention
- Validate auth with test_connection() before calling branch APIs
- Cache the branch list and refresh periodically instead of calling per-request
- Alert on this error to distinguish config drift (renamed repo, rotated token) from outages
When it happens
Trigger: Calling get_branches against a repository slug that does not exist, with an expired/revoked token, with a token lacking read access to refs, or when the response body is not valid JSON (proxy interference). A 200 response missing the 'values' key is NOT an error — it returns [].
Common situations: Verifying branch configuration (e.g. checking that the configured 'branch' actually exists) in setup scripts; token rotation; wrong workspace id; API rate limiting during bulk prompt syncs.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Failed to get file metadata for
- Failed to get repository info
- Authentication failed. Check your BitBucket access token…
- Error listing files in
- Access denied to directory
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/f8ba39bdbdae2ee9.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/bitbucket/bitbucket_client.py:210
return False
def get_branches(self) -> list[dict[str, Any]]:
"""
Get list of branches in the repository.
Returns:
List of branch information dictionaries
"""
url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}/refs/branches"
try:
response: Final = self.http_handler.get(url, headers=self.headers)
response.raise_for_status()
data: Final = response.json()
return data.get("values", [])
except Exception as e:
raise Exception(f"Failed to get branches: {e}")
def get_file_metadata(self, file_path: str) -> dict[str, Any] | None:
"""
Get metadata about a file (size, last modified, etc.).
Args:
file_path: Path to the file in the repository
Returns:
Dictionary containing file metadata, or None if file not found
"""
safe_path: Final = _sanitize_file_path(file_path)
url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}/src/{self.branch}/{safe_path}"
try:
# Use GET with Range header to get just the headers (HEAD equivalent)
headers: Final = self.headers.copy()
headers["Range"] = "bytes=0-0" # Request only first byte to get headersView on GitHub (pinned to 77b7c6c40c)