microsoft/semantic-kernel · error · NotSupportedException

Google API version {apiVersion} is not supported.

Error message

Google API version {apiVersion} is not supported.

What it means

Thrown by ClientBase.GetApiVersionSubLink(GoogleAIVersion) when the enum value is neither GoogleAIVersion.V1 nor GoogleAIVersion.V1_Beta. The switch maps these two to URL path segments ('v1', 'v1beta'). Any other enum value — which can only arise from an invalid cast or a future enum member not yet handled — triggers this NotSupportedException.

Source

Thrown at dotnet/src/Connectors/Connectors.Google/Core/ClientBase.cs:115

        if (this._bearerTokenProvider is not null && await this._bearerTokenProvider().ConfigureAwait(false) is { } bearerKey)
        {
            httpRequestMessage.Headers.Authorization =
                new AuthenticationHeaderValue("Bearer", bearerKey);
        }
        else if (!string.IsNullOrWhiteSpace(this._apiKey))
        {
            httpRequestMessage.Headers.Add("x-goog-api-key", this._apiKey);
        }

        return httpRequestMessage;
    }

    protected static string GetApiVersionSubLink(GoogleAIVersion apiVersion)
        => apiVersion switch
        {
            GoogleAIVersion.V1 => "v1",
            GoogleAIVersion.V1_Beta => "v1beta",
            _ => throw new NotSupportedException($"Google API version {apiVersion} is not supported.")
        };

    protected static string GetApiVersionSubLink(VertexAIVersion apiVersion)
        => apiVersion switch
        {
            VertexAIVersion.V1 => "v1",
            VertexAIVersion.V1_Beta => "v1beta1",
            _ => throw new NotSupportedException($"Vertex API version {apiVersion} is not supported.")
        };

    /// <summary>
    /// Gets the Vertex AI endpoint base URI for the given location.
    /// The global location uses <c>https://aiplatform.googleapis.com</c> while
    /// regional locations use <c>https://{location}-aiplatform.googleapis.com</c>.
    /// </summary>
    protected static string GetVertexAIBaseUri(string location)
        => string.Equals(location, "global", StringComparison.OrdinalIgnoreCase)
            ? "https://aiplatform.googleapis.com"

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use GoogleAIVersion.V1 or GoogleAIVersion.V1_Beta explicitly when configuring the connector.
  2. If a new API version is needed, upgrade the Connectors.Google package to a release that supports it.
  3. Avoid casting arbitrary integers to GoogleAIVersion; use the named enum values.

Example fix

// before — invalid cast
var version = (GoogleAIVersion)someInt;

// after — use named enum value
var version = GoogleAIVersion.V1;
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(GoogleAIVersion), apiVersion) ||
    (apiVersion != GoogleAIVersion.V1 && apiVersion != GoogleAIVersion.V1_Beta))
{
    throw new ArgumentOutOfRangeException(nameof(apiVersion),
        $"GoogleAIVersion must be V1 or V1_Beta. Got {apiVersion}.");
}

Type guard

static bool IsSupportedGoogleVersion(GoogleAIVersion v) =>
    v == GoogleAIVersion.V1 || v == GoogleAIVersion.V1_Beta;

Try / catch

null

Prevention

When it happens

Trigger: Casting an arbitrary integer to GoogleAIVersion that does not correspond to V1 or V1_Beta. A future SDK version adds a new GoogleAIVersion enum member (e.g. V2) that this connector version does not handle. Using '(GoogleAIVersion)999' or similar invalid casts.

Common situations: Library version mismatch where a newer Google AI SDK introduces a new enum value not supported by the current Semantic Kernel connector. Reflective or dynamic code that casts integers to enums. Unit tests that construct invalid enum values.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/1df39681939b9a06. Report an issue: GitHub.