feat: add Vertex AI support via use-vertex inputs#98
Open
nh3500 wants to merge 1 commit intoanthropics:mainfrom
Open
feat: add Vertex AI support via use-vertex inputs#98nh3500 wants to merge 1 commit intoanthropics:mainfrom
nh3500 wants to merge 1 commit intoanthropics:mainfrom
Conversation
…roject-id The action currently requires an Anthropic API key and routes all calls to api.anthropic.com. This makes it unusable for organizations that have standardized on Google Cloud and want to consolidate Claude billing/access through Vertex AI. This change adds an optional Vertex AI path. The main `claude` CLI subprocess already supports Vertex out of the box via the `CLAUDE_CODE_USE_VERTEX` / `ANTHROPIC_VERTEX_PROJECT_ID` / `CLOUD_ML_REGION` env vars; the only Python code that hardcoded the direct-API client was the false-positive findings filter (`ClaudeAPIClient`), which now accepts `use_vertex=True` and constructs `AnthropicVertex(region=..., project_id=...)` instead of `Anthropic(api_key=...)`. Auth for Vertex mode is taken from Application Default Credentials, so callers run `google-github-actions/auth` (or equivalent) before this action — the action itself doesn't take credentials directly. Action surface: - New inputs: `use-vertex` (default false), `vertex-region` (default 'global'), `vertex-project-id`. - `claude-api-key` is now optional (was required); the auth check passes if either an API key OR `use-vertex` + project-id are set. - New env passthrough to the runtime: CLAUDE_CODE_USE_VERTEX, ANTHROPIC_VERTEX_PROJECT_ID, CLOUD_ML_REGION. Behavior on the existing direct-API path is unchanged: all defaults preserve the old behavior, and the existing test suite passes without modification beyond a kwargs assertion update for the new optional fields. Tests: - Added test_claude_api_client.py covering both direct and Vertex constructors, env-var fallback, missing-project error, and the Vertex-skips-proactive-validation behavior. - Added two Vertex coverage cases in test_helper_functions.py for `initialize_findings_filter` (vertex env enables filtering; vertex-without-project falls back to hard exclusions). - Full suite: 183/183 passing locally. Why skip validation in Vertex mode: the existing validate_api_access sends a probe request to `claude-3-5-haiku-20241022`. On Vertex, that specific model has to be enabled in the caller's GCP project, which isn't guaranteed and would produce confusing failures. Real auth/quota issues will surface on the first actual filter call, which already has retry and error handling, so the pre-flight probe adds no value here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional Vertex AI path to the action, alongside the existing
claude-api-keyflow. Motivation: organizations that have standardized on Google Cloud often want Claude billing and access centralized in Vertex AI rather than managing per-repoANTHROPIC_API_KEYsecrets — for those teams, the current required-API-key surface makes this action unusable.This change is fully backward-compatible: every existing default preserves the current behavior, and only the addition of new optional kwargs to
FindingsFilterrequires touching one existing test assertion.What changes
New action inputs
use-vertex'false'vertex-region'global'global,us-east5)vertex-project-id''use-vertexis trueclaude-api-keyis nowrequired: false(wastrue). The action's auth pre-flight check now passes if either an API key oruse-vertex+vertex-project-idare provided. The direct-API call sites are unchanged.Code changes
The action has two Claude call points:
SimpleClaudeRunnerspawns theclaudeCLI as a subprocess. Claude Code natively supports Vertex viaCLAUDE_CODE_USE_VERTEX=1+ANTHROPIC_VERTEX_PROJECT_ID+CLOUD_ML_REGION. No code change needed — just env passthrough inaction.yml.ClaudeAPIClientconstructsAnthropic(api_key=...)directly. Now acceptsuse_vertex=Trueand constructsAnthropicVertex(region=..., project_id=...)instead. Auth uses Application Default Credentials, so callers must rungoogle-github-actions/authbefore invoking this action.The proactive
validate_api_access()probe is skipped in Vertex mode. Reason: it currently callsclaude-3-5-haiku-20241022as a low-cost test, but on Vertex that specific model must be enabled in the caller's GCP project, which is not guaranteed and would produce confusing failures. Real auth/quota errors still surface on the first actual filter call (which has its own retry/error handling), so the pre-flight probe added no value in Vertex mode.Example usage
Tests
test_claude_api_client.pycovering both constructors, env-var fallback, missing-project error path, and the validation-skip behavior in Vertex mode.test_helper_functions.pyforinitialize_findings_filter:ANTHROPIC_VERTEX_PROJECT_IDfalls back to hard-exclusions-onlyBackward compatibility
Every change is additive:
False/Noneuse-vertexis not setExisting users see no behavior difference and don't need to change their workflow files.
Why this is worth merging
ANTHROPIC_API_KEYfor GCP-centric orgs — Vertex auth via WIF is more secure (short-lived tokens, IAM-controlled, no per-repo secret management).claude-code-actionwhich already acceptsuse_vertex: 'true'— this brings the security review action to parity.Test plan
@v...