personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: pass project_id from SA JSON to genai.Client for Vertex AI

The google-genai SDK calls google.auth.default() when credentials
are passed without a project, causing "default credentials not found"
errors. Read project_id from the service account JSON and pass it
explicitly alongside the credentials object.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+25 -2
+13 -2
tests/test_validate_key.py
··· 135 135 assert mock_cls.call_args.kwargs["api_key"] == "test-key" 136 136 137 137 138 - def test_validate_vertex_credentials(): 138 + def test_validate_vertex_credentials(tmp_path): 139 139 """validate_vertex_credentials creates SA-authenticated client.""" 140 + import json 141 + 142 + sa_file = tmp_path / "sa.json" 143 + sa_file.write_text(json.dumps({ 144 + "type": "service_account", 145 + "project_id": "test-project", 146 + "client_email": "test@project.iam.gserviceaccount.com", 147 + "private_key": "fake", 148 + })) 149 + 140 150 client = Mock() 141 151 client.models.list.return_value = [Mock()] 142 152 ··· 152 162 return_value=mock_creds, 153 163 ), 154 164 ): 155 - result = think.providers.google.validate_vertex_credentials("/tmp/sa.json") 165 + result = think.providers.google.validate_vertex_credentials(str(sa_file)) 156 166 157 167 assert result == { 158 168 "valid": True, ··· 160 170 } 161 171 assert mock_cls.call_args.kwargs["vertexai"] is True 162 172 assert mock_cls.call_args.kwargs["credentials"] is mock_creds 173 + assert mock_cls.call_args.kwargs["project"] == "test-project" 163 174 assert "api_key" not in mock_cls.call_args.kwargs 164 175 165 176
+12
think/providers/google.py
··· 154 154 } 155 155 156 156 if creds_path and os.path.exists(creds_path): 157 + import json as _json 158 + 157 159 from google.oauth2.service_account import Credentials 158 160 159 161 creds = Credentials.from_service_account_file( ··· 161 163 scopes=["https://www.googleapis.com/auth/cloud-platform"], 162 164 ) 163 165 client_kwargs["credentials"] = creds 166 + with open(creds_path, encoding="utf-8") as _f: 167 + _sa_data = _json.load(_f) 168 + if "project_id" in _sa_data: 169 + client_kwargs["project"] = _sa_data["project_id"] 164 170 elif not os.getenv("GOOGLE_APPLICATION_CREDENTIALS"): 165 171 raise ValueError( 166 172 "Vertex AI backend requires service account credentials. " ··· 803 809 Returns {"valid": True, "email": "..."} or {"valid": False, "error": "..."}. 804 810 """ 805 811 try: 812 + import json as _json 813 + 806 814 from google.oauth2.service_account import Credentials 807 815 808 816 creds = Credentials.from_service_account_file( ··· 814 822 "credentials": creds, 815 823 "http_options": types.HttpOptions(timeout=10000), 816 824 } 825 + with open(creds_path, encoding="utf-8") as _f: 826 + _sa_data = _json.load(_f) 827 + if "project_id" in _sa_data: 828 + client_kwargs["project"] = _sa_data["project_id"] 817 829 818 830 client = genai.Client(**client_kwargs) 819 831 list(client.models.list(config={"page_size": 1}))