Skip to content

Map provider credential failures to ErrorReason.INVALID_CREDENTIALS in all model plugins #101

Open

Description

@huangjeff5

With #49, Gemini and Vertex tag a rejected credential with ErrorReason.INVALID_CREDENTIALS. The reason travels in details['reason'], so app code can branch on it no matter which plugin raised:

response = await ai.generate(prompt='Suggest a dish.', context={'secrets': {'api_key': tenant_key}})
if response.error and response.error.reason is ErrorReason.INVALID_CREDENTIALS:
    ...  # ask the tenant for a new key

reason is the cross-plugin contract in Python. The other model plugins still set only a status. Each one should pass reason=ErrorReason.INVALID_CREDENTIALS to provider_error(...) when the provider says the key or token it got is bad.

Scope:

  • Only credentials the provider rejected. A missing key is a separate decision; leave it as it is.
  • Permission errors (403, AccessDenied) don't get the reason. The credential worked; it just can't do this.

anthropic

  • Where: genkit_anthropic/_models.py:_from_anthropic_error.
  • Signal: body error.type == 'authentication_error', which is HTTP 401 and anthropic.AuthenticationError. Today it maps to UNAUTHENTICATED with no reason.
  • Not this: permission_error (403).

openai (and OpenAI-compatible endpoints built on it)

  • Where: genkit_openai/_models/_utils.py:reraise_openai_error. An APIStatusError goes to provider_error(http_status=...).
  • Signal: openai.AuthenticationError (401), or body error.code == 'invalid_api_key'.

amazon-bedrock

  • Where (service errors): genkit_amazon_bedrock/_models.py:_from_client_error, through the _ERROR_CODE_STATUS table.
  • Signal: UnrecognizedClientException and ExpiredTokenException.
  • Not this: AccessDeniedException, which is an IAM or model-access problem.
  • Where (client-side errors): _models.py:_from_botocore_error, through _BOTOCORE_ERROR_STATUS.
  • Signal: UnauthorizedSSOTokenError and TokenRetrievalError. NoCredentialsError and PartialCredentialsError mean the credentials are missing, which is out of scope.
  • _embedders.py and _image.py share these helpers.

vertexai (Model Garden)

  • Where: genkit_vertexai/_model_garden/_client.py:_refresh_credentials.
  • Signal: a non-transient RefreshError. A DefaultCredentialsError means the credentials are missing, which is out of scope.
  • Copy genkit_google_genai/_auth.py:raise_auth_error.

ollama

  • A local server has no auth, so there's nothing to map.
  • Behind an auth proxy: the failure shows up as ollama.ResponseError in _models.py, _embedders.py and _plugin.py, through provider_error(http_status=e.status_code).
  • Signal: status_code == 401.

Each plugin should get a test that checks the reason both ways: on response.error.reason when generate returns the failure, and on GenkitError.reason when a call raises (embed, model listing).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions