Skip to content

Commit ae3a0e5

Browse files
committed
Feature: Enable programmatically pass in api_key besides reading from env
1 parent d181b27 commit ae3a0e5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

docs/docs/ai/llm.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ To use the Vertex AI API:
234234
gcloud auth application-default login
235235
```
236236

237+
:::note API Key Not Supported
238+
239+
Vertex AI does **not** support the `api_key` parameter. Vertex AI uses Application Default Credentials (ADC) for authentication instead of API keys. If you provide an `api_key` parameter when using `LlmApiType.VERTEX_AI`, an error will be raised.
240+
241+
:::
242+
237243
Spec for Vertex AI takes additional `api_config` field, in type `cocoindex.llm.VertexAiConfig` with the following fields:
238244
- `project` (type: `str`, required): The project ID of the Google Cloud project.
239245
- `region` (type: `str`, optional): The region of the Google Cloud project. Use `global` if not specified.

rust/cocoindex/src/llm/gemini.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,15 @@ static SHARED_RETRY_THROTTLER: LazyLock<SharedRetryThrottler> =
275275
impl VertexAiClient {
276276
pub async fn new(
277277
address: Option<String>,
278-
_api_key: Option<String>,
278+
api_key: Option<String>,
279279
api_config: Option<super::LlmApiConfig>,
280280
) -> Result<Self> {
281281
if address.is_some() {
282282
api_bail!("VertexAi API address is not supported for VertexAi API type");
283283
}
284+
if api_key.is_some() {
285+
api_bail!("VertexAi API key is not supported for VertexAi API type. Vertex AI uses Application Default Credentials (ADC) for authentication. Please set up ADC using 'gcloud auth application-default login' instead.");
286+
}
284287
let Some(super::LlmApiConfig::VertexAi(config)) = api_config else {
285288
api_bail!("VertexAi API config is required for VertexAi API type");
286289
};

0 commit comments

Comments
 (0)