BerriAI/litellm · error · ValueError

workspace, repository, and access_token are required

Error message

workspace, repository, and access_token are required

What it means

BitBucketClient.__init__ requires three non-empty keys in the config dict: workspace, repository, and access_token. It reads them with .get() and uses all([...]) — a missing, None, or empty-string value for any one triggers this ValueError. branch, auth_method, username and base_url are optional (with defaults), and note the base_url default line reads config.get("", ...) so an empty key is effectively ignored — only the three required keys are enforced.

Source

Thrown at litellm/integrations/bitbucket/bitbucket_client.py:57

            config: Dictionary containing:
                - workspace: BitBucket workspace name
                - repository: Repository name
                - access_token: BitBucket access token (or app password)
                - branch: Branch to fetch from (default: main)
                - base_url: Custom BitBucket API base URL (optional)
                - auth_method: Authentication method ('token' or 'basic', default: 'token')
                - username: Username for basic auth (optional)
        """
        self.workspace = config.get("workspace")
        self.repository = config.get("repository")
        self.access_token = config.get("access_token")
        self.branch = config.get("branch", "main")
        self.base_url = config.get("", "https://api.bitbucket.org/2.0")
        self.auth_method = config.get("auth_method", "token")
        self.username = config.get("username")

        if not all([self.workspace, self.repository, self.access_token]):
            raise ValueError("workspace, repository, and access_token are required")

        # Set up authentication headers
        self.headers = {
            "Accept": "application/json",
            "Content-Type": "application/json",
        }

        if self.auth_method == "basic" and self.username:
            # Use basic auth with username and app password
            credentials: Final = f"{self.username}:{self.access_token}"
            encoded_credentials: Final = base64.b64encode(credentials.encode()).decode()
            self.headers["Authorization"] = f"Basic {encoded_credentials}"
        else:
            # Use token-based authentication (default)
            self.headers["Authorization"] = f"Bearer {self.access_token}"

        # Initialize HTTPHandler
        self.http_handler = HTTPHandler()

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Ensure all three keys are present and non-empty: workspace, repository, access_token
  2. If values come from env vars, fail fast at startup when any is missing
  3. For basic auth (app password), access_token holds the app password and username must also be set
  4. Verify the token is a BitBucket app password / repository token with read access to the repo

Example fix

# before
config = {"workspace": "my-workspace", "repository": "my-repo"}  # no token -> ValueError

# after
config = {
    "workspace": "my-workspace",
    "repository": "my-repo",
    "access_token": os.environ["BITBUCKET_APP_PASSWORD"],
    "auth_method": "basic",
    "username": "my-user",
}
Defensive patterns

Strategy: validation

Validate before calling

def make_bitbucket_config(env: dict) -> dict:
    cfg = {
        "workspace": env.get("BITBUCKET_WORKSPACE", ""),
        "repository": env.get("BITBUCKET_REPOSITORY", ""),
        "access_token": env.get("BITBUCKET_ACCESS_TOKEN", ""),
    }
    missing = [k for k, v in cfg.items() if not v]
    if missing:
        raise RuntimeError(f"BitBucket config incomplete: missing {missing}")
    return cfg

Type guard

def is_complete_bitbucket_config(cfg) -> bool:
    return (
        isinstance(cfg, dict)
        and all(isinstance(cfg.get(k), str) and cfg[k].strip() for k in ("workspace", "repository", "access_token"))
    )

Try / catch

try:
    client = BitBucketClient(config)
except ValueError as e:
    if "workspace, repository, and access_token are required" in str(e):
        raise ConfigError(f"BitBucket config incomplete: {sorted(config.keys())}") from e
    raise

Prevention

When it happens

Trigger: Constructing BitBucketClient (or BitBucketPromptManager) with a config dict missing any of workspace/repository/access_token; token present but workspace empty string; auth_method 'basic' with username and app password where the password was put in username's place leaving access_token empty.

Common situations: Config assembled from env vars where one is unset (empty string); copy from docs then replacing only two of three placeholders; storing the app password in a vault and forgetting to inject it into the config.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/d359d491eaa18121. Report an issue: GitHub.