BerriAI/litellm · error · ValueError
project and access_token are required
Error message
project and access_token are required
What it means
First of two guards in GitLabClient.__init__: raised when config.get('project') or config.get('access_token') returns None, i.e. the keys are entirely absent from gitlab_config. The second guard (line 53) catches falsy-but-present values like empty strings, so this one specifically means the keys are missing.
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 6c2dcb801b)
Solutions
- Include both keys in gitlab_config: project (e.g. 'group/subgroup/repo' or numeric ID) and access_token.
- Use the exact key names — 'project' and 'access_token'; rename 'repo'/'token'/'pat' accordingly.
- If loading from environment, ensure the token variable is set before config construction, not lazily.
Example fix
# before
gitlab_config = {"repo": "acme/api", "token": "glpat-..."}
# after
gitlab_config = {"project": "acme/api", "access_token": "glpat-..."} Defensive patterns
Strategy: validation
Validate before calling
def build_gitlab_config(project: str | None, access_token: str | None) -> dict:
if project is None or access_token is None:
raise ValueError("gitlab_config requires both 'project' and 'access_token' keys")
return {"project": project, "access_token": access_token} Type guard
def has_project_and_token_keys(cfg: dict) -> bool:
return isinstance(cfg, dict) and "project" in cfg and "access_token" in cfg Prevention
- Use the canonical key names 'project' and 'access_token' everywhere, including IaC templates.
- Add schema validation (e.g. pydantic) over gitlab_config at config load.
When it happens
Trigger: Constructing GitLabClient (or the GitLab prompt integration) with a gitlab_config dict that lacks 'project' or 'access_token'; keys present but named differently ('repo', 'token', 'private_token') so .get returns None.
Common situations: Translating git CLI URLs into config by hand and using 'repo' instead of 'project'; config templating that strips secret keys when the token env var is undefined; onboarding from GitLab CI docs where the variable is named CI_JOB_TOKEN.
Related errors
- gitlab_config is required for gitlab prompt integration
- Event hook {hook} is not in the supported event hooks {suppo
- Event hook {event_hook} is not in the supported event hooks
- Invalid environment: {environment}. Please use one of the fo
- bucket_name must be provided for S3 destination
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/a64defb24dd0c885.
Report an issue: GitHub.