BerriAI/litellm · error · ValueError

Either 'model' or 'agent' must be provided

Error message

Either 'model' or 'agent' must be provided

What it means

Request validation in GoogleAIStudioInteractionsConfig.transform_request. The Interactions API body must identify either a model or an agent; if both are falsy (None or empty string) the transform raises before any HTTP call. If model is set it is normalized through get_base_model (strips a 'gemini/' prefix); agent is passed through as-is.

Solutions

  1. Pass a model: litellm.interactions.create(model='gemini-2.5-flash', input=...)
  2. Or an agent id: litellm.interactions.create(agent='agents/my-agent', input=...)
  3. Validate at your API boundary: reject requests where both model and agent are missing before calling litellm
  4. Check for typos/dead kwargs — misspelled parameters are silently ignored, leaving model=None

Example fix

# before
r = litellm.interactions.create(input={'text': 'hi'}, api_key=KEY)
# ValueError: Either 'model' or 'agent' must be provided

# after
r = litellm.interactions.create(
    model=cfg.get('model') or 'gemini-2.5-flash',  # explicit default
    input={'text': 'hi'},
    api_key=KEY,
)
Defensive patterns

Strategy: validation

Validate before calling

def valid_interaction_target(model: str | None, agent: str | None) -> bool:
    return bool(model or agent)

assert valid_interaction_target(cfg.get('model'), cfg.get('agent')), \
    "interactions.create requires 'model' or 'agent'"

Prevention

When it happens

Trigger: litellm.interactions.create(input=...) with both model and agent omitted; passing model='' or agent='' from empty form/config fields; kwargs typos (e.g. model_name=) that leave the real parameters None.

Common situations: Config-driven pipelines where the model key is missing in YAML/JSON and code defaults to None; UIs where the user selects neither a model nor an agent; refactors renaming the parameter and silently dropping it.

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/07a3759fb385f20a. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/gemini/interactions/transformation.py:154

        - ``response_mime_type`` is folded into ``response_format`` and stripped from
          the body (the field was removed in Api-Revision 2026-05-20).
        - ``generation_config.image_config`` is moved to a ``response_format`` entry
          with ``"type": "image"`` (also removed from generation_config in 2026-05-20).

        When on the legacy schema (use_legacy_interactions_schema=True):
        - All fields are forwarded as-is.
        """
        use_legacy: Final[bool] = litellm.use_legacy_interactions_schema

        request_body: Final[dict[str, Any]] = {}

        # Model or Agent (one required)
        if model:
            request_body["model"] = GeminiModelInfo.get_base_model(model) or model
        elif agent:
            request_body["agent"] = agent
        else:
            raise ValueError("Either 'model' or 'agent' must be provided")

        # Input
        if input is not None:
            request_body["input"] = input

        # Pass through optional params — legacy schema keeps all fields as-is.
        optional_keys: Final = [
            "tools",
            "system_instruction",
            "stream",
            "store",
            "background",
            "environment",
            "response_modalities",
            "previous_interaction_id",
        ]
        for key in optional_keys:
            if optional_params.get(key) is not None:

View on GitHub (pinned to 77b7c6c40c)