BerriAI/litellm · error · ValueError

project and access_token are required

Error message

project and access_token are required

What it means

GitLabClient.__init__ requires both 'project' and 'access_token' keys in the config dict. This first check uses config.get(), so it raises only when a key is absent or explicitly None. project is the 'group/subgroup/repo' path or a numeric project id; access_token is a PAT or OAuth token that will be str()-coerced.

Solutions

  1. Include both keys: {'project': 'group/repo', 'access_token': '<token>'}
  2. Load env vars with an explicit None check and fail fast when missing
  3. Validate the config dict keys before constructing the client

Example fix

# before
config = {"project": "mygroup/myrepo"}
client = GitLabClient(config)

# after
config = {
    "project": "mygroup/myrepo",
    "access_token": os.environ["GITLAB_TOKEN"],
}
client = GitLabClient(config)
Defensive patterns

Strategy: validation

Validate before calling

REQUIRED_GITLAB_KEYS = ("project", "access_token")


def validate_gitlab_config(config: dict) -> None:
    missing = [k for k in REQUIRED_GITLAB_KEYS if config.get(k) is None]
    if missing:
        raise ValueError(f"gitlab config missing required keys: {missing}")

Type guard

from typing import Any


def is_complete_gitlab_config(config: Any) -> bool:
    """True when both project and access_token keys are present (not None)."""
    return (
        isinstance(config, dict)
        and config.get("project") is not None
        and config.get("access_token") is not None
    )

Try / catch

try:
    client = GitLabClient(config)
except ValueError as e:
    if "project and access_token are required" in str(e):
        raise RuntimeError(
            "gitlab_config needs non-None 'project' and 'access_token'"
        ) from e
    raise

Prevention

When it happens

Trigger: Constructing GitLabClient (directly or via GitLabPromptManager / the initializers) with a dict missing 'project' or 'access_token'; keys spelled differently (projectId, token, accessToken); values explicitly None from os.getenv() without a default.

Common situations: Config assembled from environment variables where one variable is unset; config schema drift between environments; copy-pasting an example config with the token line removed; passing the GitLab URL instead of a project path.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/a64defb24dd0c885. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/gitlab/gitlab_client.py:41

    """

    def __init__(self, config: dict[str, Any]):
        """
        Initialize the GitLab client.

        Args:
            config: Dictionary containing:
                - project: Project path ("group/subgroup/repo") or numeric project ID (str|int) [required]
                - access_token: GitLab personal/access token or OAuth token [required] (str)
                - auth_method: 'token' (default; sends Private-Token) or 'oauth' (Authorization: Bearer)
                - tag: Tag name to fetch from (takes precedence over branch if provided)
                - branch: Branch to fetch from (default: "main")
                - base_url: Base GitLab API URL (default: "https://gitlab.com/api/v4")
        """
        project: Final = config.get("project")
        access_token: Final = config.get("access_token")
        if project is None or access_token is None:
            raise ValueError("project and access_token are required")

        self.project: str | int = project
        self.access_token: str = str(access_token)
        self.auth_method = config.get("auth_method", "token")  # 'token' or 'oauth'
        self.branch = config.get("branch", None)
        if not self.branch:
            self.branch = "main"
        self.tag = config.get("tag")
        self.base_url = config.get("base_url", "https://gitlab.com/api/v4")

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

        # Effective ref: prefer tag if provided, else branch ("main")
        self.ref = str(self.tag or self.branch)

        # Build headers
        self.headers = {

View on GitHub (pinned to 77b7c6c40c)