Skip to content

Supporting the use of Provisioned Throughput with an API Key #1931

@aletundo

Description

@aletundo

Is your feature request related to a problem? Please describe.
The Use Provisioned Throughput documentation page shows only the REST option as a viable approach for using Provisioned Throughput for a specific project, Google model, and region with an API Key.

Describe the solution you'd like
I'd like the SDK to support this use case, which is currently impossible because if both Project ID, Location and API Key are specified, the client raises a ValueError exception (see google/genai/_api_client.py#L559-L565)

    # Validate explicitly set initializer values.
    if (project or location) and api_key:
      # API cannot consume both project/location and api_key.
      raise ValueError(
          'Project/location and API key are mutually exclusive in the client'
          ' initializer.'
      )

I personally did the changes necessary to make it work locally, that is:

  • Avoiding raising ValueError during client initialization to cover this use case
  • Modify _request_once and _async_request_once to NOT use Bearer token when API key is provided with project/location
  • Remove the API key from headers when it's used as a query parameter
  • Append the API key as query parameter

I could work on a PR if needed.

Describe alternatives you've considered

  • I'll for now directly use the REST API.
  • Using ADC it's currently not a viable solution.

Additional context
None.

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions