Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) by yusuke0610 · Pull Request #401 · yusuke0610/devforge · GitHub
Skip to content

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015) - #401

Merged
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers
Jun 24, 2026
Merged

feat(agent): Gemini/Anthropic を Vertex AI(SA→ADC)経由に移行(ADR-0015)#401
yusuke0610 merged 5 commits into
mainfrom
feat/vertex-ai-llm-providers

Conversation

@yusuke0610

@yusuke0610yusuke0610 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

職務経歴書(PII)を扱う本番環境として、Gemini Developer API の無料枠(学習リスク)を廃止。Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)に切り替え、シークレットを OpenAI キー 1 本に削減。

  • Google Gemini: asia-northeast1(Tokyo)で Vertex 経由に
  • Anthropic Claude: asia-southeast1(Singapore)で Vertex 経由に(Tokyo 未提供のため最寄り)
  • OpenAI GPT: API キー継続(GCP に無い)

技術変更

  • google_client.py: genai.Client(vertexai=True, project, location)
  • anthropic_client.py: AsyncAnthropicVertex(project_id, region)
  • model_catalog.py: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に統一
  • 環境変数:ANTHROPIC_API_KEY / GOOGLE_API_KEY 廃止、VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION 追加
  • requirements.txt: anthropic[vertex] で ADC 対応
  • infra(cloud_run): 注入を OpenAI キーのみに絞り込み(secret コンテナ削除は別 PR)

検証

  • make ci (lint + test): pass ✅
  • Backend テスト: 582 green ✅
  • OpenAPI drift: なし ✅
  • infra fmt-check: pass ✅

トレードオフ

  • regional endpoint 課金: Claude の Singapore regional は global 比 +10% プレミアム(PII 保護優先)
  • ローカル・CI: LLM_LOCAL_OLLAMA=1 で Vertex を避ける(ADC 不要)。実 Vertex をローカルで試す場合のみ gcloud auth application-default login
  • 要・実デプロイ確認: asia-southeast1 での Claude 提供と model id は実デプロイで確認(pytest/CI smoke では Vertex 実呼び出し未検証)

関連

  • ADR-0015: Vertex AI / SA→ADC / リージョン戦略 / トレードオフを新規に起票
  • ADR-0013(マルチプロバイダ)の認証部分を更新

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched Gemini and Claude/Anthropic LLM access to Vertex AI using application default credentials (no API keys).
    • Updated configuration: removed ANTHROPIC_API_KEY / GOOGLE_API_KEY; added VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION (with defaults).
    • Updated Claude Haiku to the versioned Vertex-compatible model ID.
  • Documentation
    • Added ADR-0015 and updated LLM environment variable docs.
  • Tests
    • Updated LLM client and billing expectations for Vertex and the versioned model ID.
  • Infra
    • Updated Cloud Run secret/env injection behavior and Cloudflare CNAME resource/TTL handling.
    • Refreshed Terraform/OpenTofu provider lock files.

職務経歴書(PII)の学習リスク回避のため Gemini Developer API 無料枠を廃し、
Gemini と Anthropic を Vertex AI(Cloud Run の SA → ADC)経由に切り替える。
OpenAI のみ GCP に存在しないため API キーを継続する。
- google_client: genai.Client(vertexai=True, project, location) 化
- anthropic_client: AsyncAnthropicVertex(project_id, region) 化(generate は無変更)
- model_catalog: Haiku を Vertex 版 ID(claude-haiku-4-5@20251001)に
(Sonnet 4.6 / Gemini は同 ID)
- settings/env_keys: API キー getter を GCP_PROJECT_ID + VERTEX_LOCATION /
VERTEX_ANTHROPIC_LOCATION に置換(Gemini=Tokyo / Claude=Singapore)
- requirements: anthropic[vertex](ADC 用 google-auth)
- infra(cloud_run): ANTHROPIC_API_KEY/GOOGLE_API_KEY 注入停止・Vertex location 注入追加
(secret コンテナ削除は別 PR)
- docker-compose / docs/api.md 更新・ADR-0015 起票
- tests: key 未設定→project 未設定に置換、billing の Haiku model_id assert を更新
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d871ef7-3a0f-4213-977a-80ae315200fc

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5fae and 84e503f.

📒 Files selected for processing (3)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

📝 Walkthrough

Walkthrough

Migrates Gemini and Anthropic LLM clients to Vertex AI using GCP project and region configuration, updates related docs, tests, and runtime wiring, versions the Haiku model ID, and refreshes Terraform provider locks plus Cloudflare resource naming.

Changes

Vertex AI Migration

Layer / File(s)Summary
Env and settings contract
backend/app/core/env_keys.py, backend/app/core/settings.py, backend/requirements.txt
Removes Anthropic/Google API-key env access, adds GCP project and Vertex location getters, and enables the Anthropic Vertex extra dependency.
GCP project validation
backend/app/services/agent/llm/base.py
Adds require_gcp_project for empty-project validation.
Vertex client initialization
backend/app/services/agent/llm/anthropic_client.py, backend/app/services/agent/llm/google_client.py
Switches both LLM clients to Vertex AI initialization with GCP project and region settings.
Haiku model ID update
backend/app/services/agent/model_catalog.py
Pins the Haiku model ID to claude-haiku-4-5@20251001.
Cloud Run and local env wiring
infra/modules/cloud_run/variables.tf, infra/modules/cloud_run/main.tf, docker-compose.yml
Adds Vertex region inputs, injects Vertex location env vars, and changes secret injection to match the new provider setup.
Docs and test updates
docs/adr/0015-vertex-ai-for-gemini-anthropic.md, docs/api.md, backend/tests/test_llm_clients.py, backend/tests/test_billing.py
Documents the Vertex migration and updates client and billing tests for the new auth and model ID behavior.

Infrastructure Maintenance

Layer / File(s)Summary
Terraform provider repins
infra/environments/dev/.terraform.lock.hcl, infra/environments/prod/.terraform.lock.hcl, infra/environments/stg/.terraform.lock.hcl
Updates Cloudflare, Google, and Turso provider versions, constraints, and hashes across environments.
Cloudflare DNS resource rename
infra/modules/cloudflare/main.tf
Renames the Cloudflare DNS record resource and adds a moved state block.
AGENTS simplification
AGENTS.md
Replaces the detailed guide with a single pointer to .claude/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yusuke0610/devforge#331: Shares the same LLM configuration surface in env_keys.py, settings.py, and the Google/Anthropic client wiring.
  • yusuke0610/devforge#321: Touches the same LLM env and Anthropic client areas that this PR rewires for Vertex AI.
  • yusuke0610/devforge#332: Modifies the same anthropic_client.py and shared LLM helper path used here.

Suggested labels

feature

Poem

🐇 Hop, hop, the keys are gone,
Vertex regions shine at dawn.
GCP and ADC align,
Claude and Gemini work just fine.
One little rabbit gives a cheer,
“Keyless clouds are now right here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedGemini/Anthropic の Vertex AI への移行と ADR-0015 を端的に示しており、変更内容の मुख्य点と一致しています。
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-ai-llm-providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Around line 42-43: The VERTEX_LOCATION and VERTEX_ANTHROPIC_LOCATION
environment variables in docker-compose.yml are using bare variable substitution
syntax without default values, which causes unset variables to become empty
strings instead of allowing the backend to apply its own fallback defaults.
Modify both variable references to include default values using the Docker
Compose syntax of ${VARIABLE_NAME:-default_value}, ensuring that when these
environment variables are not set, appropriate default values are used instead
of empty strings to prevent Vertex clients from being initialized with blank
locations.
In `@infra/modules/cloud_run/main.tf`:
- Around line 12-16: The deprecated `anthropic-api-key` and `google-api-key`
entries are still present in `local.secret_names`, which causes unnecessary IAM
permissions to be granted to the Cloud Run service account even though these
secrets are no longer used after the Vertex AI migration. Remove both the
`anthropic-api-key` and `google-api-key` strings from the `local.secret_names`
list to follow least privilege IAM principles and ensure the Cloud Run service
account only has access to the secrets it actually needs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7aec2cd-6897-4d2b-ae41-b8e4c8f49a52

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 609eaf5.

📒 Files selected for processing (14)
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf

Comment threaddocker-compose.yml Outdated
Comment threadinfra/modules/cloud_run/main.tf Outdated
yusuke0610and others added 3 commits June 23, 2026 16:54
versions.tf が cloudflare ~> 5.0 を要求しているのに lock が v4 系(4.52.7)を
pin したままで、infra を触る PR の opentofu-validate が provider 解決段階で
失敗していた(main 由来の既存ドリフト。本 PR が初の infra 変更で顕在化)。
- cloudflare provider を v5.21.0 に更新(turso 1.2.0 / google 7.37.0 も追従)
- cloudflare_record → cloudflare_dns_record(v5 改名)、value → content、
ttl=1 を明示(v5 で必須)。use_custom_domain は全環境 false で count=0 の
ため移行対象インスタンスは無く moved ブロックは不要
- dev/stg/prod の lock を linux_amd64 + darwin_arm64 の両プラットフォームで再生成
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- docker-compose: VERTEX_LOCATION / VERTEX_ANTHROPIC_LOCATION に :-既定値 を付与。
bare の ${VAR} は未設定時に空文字を注入し backend の os.getenv フォールバックを
潰すため(Vertex client が空ロケーションで初期化される)
- cloud_run: Vertex 移行で未使用になった anthropic-api-key / google-api-key を
secret_names から削除(コンテナと secretAccessor を destroy / least privilege)。
本 PR で注入廃止と同時に削除する方針に変更(当初の別 PR 分離を取りやめ)
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610

Copy link
Copy Markdown
OwnerAuthor

@coderabbitai RVして

@coderabbitai

coderabbitaiBot commented Jun 23, 2026

Copy link
Copy Markdown

@yusuke0610 了解です!PR #401 のレビューを開始します 🐇

✅ Action performed

Full review finished.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr/0015-vertex-ai-for-gemini-anthropic.md`:
- Line 47: The ADR statement at line 47 describing the deprecated secret
retention strategy is inconsistent with the current infrastructure
implementation in infra/modules/cloud_run/main.tf, which already removes
anthropic-api-key and google-api-key from the secret_names list. Update the ADR
documentation to reflect the actual current state where these secrets are
already being excluded and will be deleted on the next terraform apply, rather
than stating they will be retained for deletion in a separate PR.
In `@infra/modules/cloud_run/variables.tf`:
- Around line 67-77: Add validation blocks to both the vertex_location and
vertex_anthropic_location variables to ensure they only accept non-empty string
values. Use a Terraform validation condition that checks the string length is
greater than zero, with an error message indicating that these variables cannot
be empty, as empty values would prevent proper Vertex AI client initialization
in Cloud Run.
In `@infra/modules/cloudflare/main.tf`:
- Around line 19-29: Add a moved block to the infra/modules/cloudflare/main.tf
file to handle the resource migration from cloudflare_record.app to
cloudflare_dns_record.app. The moved block should map the old resource state
(cloudflare_record.app) to the new resource type (cloudflare_dns_record.app) to
prevent Terraform from destroying and recreating the DNS record during the
upgrade to Cloudflare provider v5. Place this moved block in the same file where
the cloudflare_dns_record.app resource is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2956ce6c-ea41-41c8-ac80-792f0dae66ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc6f10 and 10f5fae.

📒 Files selected for processing (19)
  • AGENTS.md
  • backend/app/core/env_keys.py
  • backend/app/core/settings.py
  • backend/app/services/agent/llm/anthropic_client.py
  • backend/app/services/agent/llm/base.py
  • backend/app/services/agent/llm/google_client.py
  • backend/app/services/agent/model_catalog.py
  • backend/requirements.txt
  • backend/tests/test_billing.py
  • backend/tests/test_llm_clients.py
  • docker-compose.yml
  • docs/adr/0015-vertex-ai-for-gemini-anthropic.md
  • docs/api.md
  • infra/environments/dev/.terraform.lock.hcl
  • infra/environments/prod/.terraform.lock.hcl
  • infra/environments/stg/.terraform.lock.hcl
  • infra/modules/cloud_run/main.tf
  • infra/modules/cloud_run/variables.tf
  • infra/modules/cloudflare/main.tf

Comment threaddocs/adr/0015-vertex-ai-for-gemini-anthropic.md Outdated
Comment threadinfra/modules/cloud_run/variables.tf
Comment threadinfra/modules/cloudflare/main.tf
- cloudflare: cloudflare_record → cloudflare_dns_record の改名に moved block を追加。
全環境 use_custom_domain=false(count=0)で現状インスタンスは無いが、有効化済み
state での destroy/recreate(DNS ダウンタイム)を防ぐ防御策
- cloud_run: vertex_location / vertex_anthropic_location に空文字を弾く validation を追加
(空文字注入で backend のデフォルト補完が潰れるのを防ぐ)
- ADR-0015: 未使用シークレットを「残置(別PR削除)」→「本PRで削除」に記述を実装と整合
make infra-validate(3 環境)/ infra-fmt-check 済み。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yusuke0610
yusuke0610 merged commit 7890f46 into mainJun 24, 2026
19 checks passed
@yusuke0610
yusuke0610 deleted the feat/vertex-ai-llm-providers branch July 20, 2026 12:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@yusuke0610